Disable option if not with Javascript enabled?

Asked

Viewed 252 times

0

I am using a tag that checks if Javascript is enabled, if it is not, I would like an option on the screen to be invisible. How could I call a function if that happens? thanks

<noscript>
    Para completa funcionalidade deste site é necessário habilitar o JavaScript.
    Aqui estão as <a href="https://www.enable-javascript.com/pt/" target="_blank">
    instruções de como habilitar o JavaScript no seu navegador</a>.
</noscript>
  • I didn’t understand what you said, do you want when it enables Javascript the page to run the functions without the user having to do the refresh? That’s it?

  • I want that if javascript is disabled, I want to leave button invisibly until it enable javascript again

  • Man, I think they got you wrong. I understood that you want for example to disappear with a boot/div etc if the guy does not have Javascript enabled, is that it? If it is, what I would do is leave the element already hidden with CSS (display: None), and show it with Javascript as soon as I load the page. This way if the guy has Javascript disabled this function will never be called and the boot will remain hidden.

  • @user7349055, correct, you were the one who understood the question well, I needed a practical example

1 answer

3

There’s no way to get rid of the contents of <noscript> when the user enables Javascript, it will be necessary to do the refresh, and this only the user can do, there is no way around this, except maybe use meta=refresh to reload the page until the user has enabled Javascript, for example:

<noscript>
<!-- faz o refresh de 10 em 10 até que o usuário reabilite o cache -->
<meta http-equiv="refresh" content="10">

Para completa funcionalidade deste site é necessário habilitar o JavaScript.
Aqui estão as <a href="https://www.enable-javascript.com/pt/" target="_blank">
instruções de como habilitar o JavaScript no seu navegador</a>.
</noscript>

One of the reasons for this is because browsers have an input ("import") Javascript execution cycle, for example, if you could run a person-only function enable Javascript then functions like:

document.write

They would fail or over-write the entire page, as this type of functions needs to be executed according to the "flow" rendering DOM (of the page), so that it is necessary to reload the entire page, so that the behavior is as expected as the rendering.

Browsers even come with Javascript disabled?

I want you to understand something, it is practically impossible for a user to disable Javascript, this occurred at the time in IE 4, 5 and Netscape 4, because at the time Javascript was not enabled by default (if I am not mistaken), now really nowadays it is unlikely that the user navigates the sites without Javascript, it is very rare a site that does not depend on such technology, so the user simply could not navigate at all.

If there is any reason why the user has disabled for sure it was intentional, that is even if you put the instructions to enable it probably knows how to do and knows that you will have to give the refresh (F5, Ctrl+R, etc).

So worrying about something like this these days is really unnecessary, because if the user doesn’t want to use javascript enabled, he probably knows what javascript is and has a very good and personal motivation and will probably enable javascript when necessary, of course you can leave the message, but rest assured, if he knows how to disable he will also know how to enable and will know how to refresh after this.

  • On Samsung’s phone, user can disable javascript easily by going to menu option and disable.

  • 2

    @Matheusmiranda if he went to this is because he wanted to and for a very personal reason, if he knows how to do it, he will also know that refresh is necessary. I explained that in the answer: "If there are any reasons why the user has disabled it is absolutely intentional".

Browser other questions tagged

You are not signed in. Login or sign up in order to post.