Normally, when a page is loaded, and the browser has Javascript disabled, we use the <noscript>
tag to write something like a warning and tell the client to enable Javascript. However, Facebook, even after you load the page with JS enabled, the moment it's disabled you get a notification. How can I do something like this?
UPDATE : This mechanism is no longer available in Facebook, but it was before, I was too late in asking this question, but if any answer is found, I would really appreciate it.
What I have tried
I thought about having a segment inside my page which keeps checking if Javascript is disabled, if yes, show the contents of <noscript>
.
To Achieve this, I created a page CheckJS.html.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="0">
</head>
<body>
<noscript>
JS is disabled!
</noscript>
</body>
</html>
This page will keep on refreshing, when JS is disabled, JS is disabled! will appear.
To add this page inside my original page. I tried the following:
1- .load()
I used JQuery to .load('CheckJS.html')
inside a div
. However, it seems that .load()
only loads the contents of the <body>
of CheckJS.html. Means the <head>
element and what's 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 an <iframe>
.
<iframe src="CheckJS.html"></iframe>
However, the <meta http-equiv="refresh" content="0">
of CheckJS.html affects the parent page, the original page itself started refreshing.
If we are able to use this <iframe>
without forcing the original page to refresh, then this could be a solution, but even if this solution is found, I feel its more of a trick rather than a real solution.
UPDATE
Antony 's answer proved that I was wrong about that the iframe
refreshes the original page, the browser shows that its refreshing but actually its not, if this is it, then Javascript can be avoided, the CheckJS.html
that I provided does the job, and even better, the <noscript>
will be hidden when JS is re-enabled. Still this whole iframe approach isn't so user friendly (could freeze the browser), unless refresh occurs every 10 seconds or so, which isn't an instant detection.
Tools > Options > Content
, Javascript/JQuery functions will stop working. – Righthand