Usually, when the page loads and the browser is turned off by Javascript, we use the <noscript> tag to write something like a warning and tell the client to enable Javascript. However, Facebook, even after , you load a page with JS support enabled, and at the time of its disconnection you receive a notification. How can I do something like this?
UPDATE: this mechanism is no longer available on Facebook, but it was before, I asked this question too late, but if there is any answer, I would really appreciate it.
What i tried
I thought about the fact that there is a segment on my page that continues to check if Javascript is disabled, if so, show the contents of <noscript> .
To achieve this, I created the CheckJS.html page.
<!DOCTYPE html> <html> <head> <meta http-equiv="refresh" content="0"> </head> <body> <noscript> JS is disabled! </noscript> </body> </html>
This page will continue to update when JS is disabled, JS is disabled! .
To add this page to my original page. I tried the following:
1-.load ()
I used jQuery before .load('CheckJS.html') inside the div . However, it seems that .load() only loads the contents of <body> CheckJS.html . The <head> element also means that inside it will not be loaded inside the div .
2- iframe
After some searching, I found that the only possible way to load a FULL html page , including <head> , is to use <iframe> .
<iframe src="CheckJS.html"></iframe>
However, <meta http-equiv="refresh" content="0"> CheckJS.html affects the parent page, the original page itself began to be updated.
If we can use this <iframe> without causing the original page to refresh, this may be the solution, but even if this solution is found, I feel it is more of a trick than a real solution.
UPDATE
Anthony's answer proved that I was mistaken in the fact that iframe refreshes the original page, the browser shows that it refreshes, but in fact it is not there, if so, then Javascript can be avoided, CheckJS.html , which I provided, does the job , and even better, <noscript> will be hidden when JS is turned on again. However, this whole iframe approach is not so user-friendly (it can freeze the browser) if the update does not happen every 10 seconds or so, which is not instant detection .