<noscript> not working in Opera 11?

北战南征 提交于 2019-12-22 07:59:55

问题


I am testing my noscript tags which display content when javascript is disabled, this works in Safari, Chrome, Firefox, Camino, IE6, IE7, IE8, IE9, basically everything but Opera (I'm running version 11, not sure if its isolated to that version).

In Opera 11 nothing is displayed... is the noscript tag not supported? and what is the alternative?

Nothing surprising:

<noscript>Please enable JavaScript.</noscript>

Located between the body tags.

<html>
<body>
<script>alert('Hello World');</script>
<noscript>Hello World!</noscript>
</body>
</html>

回答1:


Are you sure you disabled javascript in Opera:

Menu >> Settings >> Preferences >> Content >> Deselect "Enable Javascript"

If so, then post the contents of your entire file here.

EDIT


Until they fix this bug in version 11 which I reckon will happen shortly you can try this:

<script type="text/javascript">
<!--

    document.write("<style type='text/css'>.noScript { display: none; }</style>");

//-->
</script>

<span class="noScript">Please enable javascript in your browser.</span>

You are basically using javascript to show css which hides the no script message, but if javascript is disabled then there is no way that css can be displayed hence the message will show.




回答2:


Uh, yeah. We (as in Opera) broke <noscript> in Opera 11. Known bug.




回答3:


Implementation of <noscript> is buggy and inconsistent and not recommended. You'd be better off doing something like:

<span class="noscript">Please enable JavaScript.</span>

You can then use JavaScript to hide anything with a class of "noscript" on page load. People with JavaScript disabled will see the message because it won't be hidden.




回答4:


Hrm. I had wrapped a meta refresh within a noscript, so that a page could automatically reload if a certain set of elements within it couldn't reload via javascript. I can't see any alternative like the hack involving hiding CSS elements. My original thought was perhaps to set a meta refresh header, but override that to not refresh at all if the javascript could execute, but I can't see any ways for javascript to redefine the page refresh time.




回答5:


try this

<span class="noscript"></span>
 <noscript>Please enable JavaScript.</noscript>



回答6:


The noscript element isn't recommended. It won't work if scripts are partially blocked (e.g. by a corporate firewall or the NoScript extension, or just a temporary DNS failure).

Build on things that work instead.




回答7:


This works well for me... (Tested in IE, Opera, and FireFox)

<p id="js_disabled">
<script type="text/javascript">
  document.getElementById('js_disabled').style.display = 'none';
</script>
  Javascript is disabled or not supported by your browser.<br/>
  Javascript must be enabled...
</p>

The JavaScript runs immediately so the noscript message never appears.

The idea is to place the JavaScript code immediately following the noscript's opening tag, in this case the paragraph tags.



来源:https://stackoverflow.com/questions/4525009/noscript-not-working-in-opera-11

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!