简体   繁体   English

noscript 标签在 Internet Explorer 上不起作用

[英]noscript tag isn't working on internet explorer

I have a website with the <noscript> tag that works just fine on all browsers except IE (7,8,9,10).我有一个带有<noscript>标签的网站,它在除 IE (7,8,9,10) 之外的所有浏览器上都可以正常工作。 After I disable scripting under the security settings inside Internet Options, On my PC only I can the the <noscript> content on IE, but on other PC's (almost all of them) I can't see the code.在 Internet 选项中的安全设置下禁用脚本后,在我的 PC 上,我只能在 IE 上查看<noscript>内容,但在其他 PC(几乎所有)上我看不到代码。 With these PC's we go with the same settings to Gmail's and FB's sites and we do get the warning for not having js enabled.使用这些 PC,我们对 Gmail 和 FB 的站点使用相同的设置,我们确实收到了未启用 js 的警告。

This is the HTML:这是 HTML:

<noscript>
    <div class="noscript">
        JavaScript must be enabled in order for you to use WEBSITE NAME in standard view.<br />
        However, it seems JavaScript is either disabled or not supported by your browser.<br />
        To use standard view, enable JavaScript by changing your browser options, then <a href="">try again</a>. 
    </div>
</noscript>

CSS: CSS:

.noscript {
    background: red;
    color: #fff;
    padding: 10px;
    text-align: center;
    position: relative;
    z-index: 3;
}

Any ideas?有任何想法吗?

Thanks!谢谢!

Encountered this issue as well.也遇到了这个问题。 I had this working in IE and then it stopped all of a sudden.我在 IE 中使用了它,然后它突然停止了。 What I found is that if your css is nested beneath a noscript tag in your actual css definition it will not work.我发现,如果您的 css 嵌套在实际 css 定义中的 noscript 标签下,它将无法工作。 If you use just a class name its fine.如果你只使用一个类名就好了。

I'm using IE 10 to test with and their dev tools to change the document mode to older browser modes to verify.我正在使用 IE 10 进行测试,并使用他们的开发工具将文档模式更改为较旧的浏览器模式进行验证。 Results may vary when actually using older browsers.实际使用旧浏览器时,结果可能会有所不同。 Report back if this is the case.如果是这种情况,请报告。

Example html:示例 html:

<noscript>
    <div class="noscript">
        JavaScript must be enabled ...
    </div>
</noscript>

Doesn't Work:不起作用:

// classes nested beneath a noscript tag are not applied by IE
noscript div.noscript {
        display: block;
        text-align: center;
        color: white;
        font-weight: 700;
        background: #D53333;
        margin: 0 auto;
        padding: 4px;
    }

Does work:是否有效:

div.noscript {
    display: block;
    text-align: center;
    color: white;
    font-weight: 700;
    background: #D53333;
    margin: 0 auto;
    padding: 4px;
}

Even I have encountered this, so after a lot of struggles, I have devised a trick that works fine.甚至我也遇到过这种情况,所以经过多次斗争,我设计了一个很好的技巧。 Instead of styling the noscript tag, cover the element to be shown when javascript is disabled in a div and then display none that div using javascript.不用设置noscript标签的样式,而是在 div 中禁用 javascript 时覆盖要显示的元素,然后使用 javascript 不显示该 div。 Hence, when javascript is disabled the viewer shall see the div you intended them to see, but if javascript is enabled the div will be styled as display none by the scrip you wrote making it not visible.因此,当 javascript 被禁用时,查看器将看到您希望他们看到的 div,但如果启用了 javascript,该 div 将被您编写的脚本设置为不显示样式,使其不可见。

See below an example:请参阅下面的示例:

Normally we do this:通常我们这样做:

  • html: <noscript> please enable javascript ... </noscript> html: <noscript> please enable javascript ... </noscript>
  • css: noscript{background-color: red; color: white; font-size: 24px; ... } CSS: noscript{background-color: red; color: white; font-size: 24px; ... } noscript{background-color: red; color: white; font-size: 24px; ... }

Instead do this:而是这样做:

  • html: <div class="noscript"> please enable javascript </div> html: <div class="noscript"> please enable javascript </div>
  • css: .noscript{background-color: red; color: white; font-size: 24px; ... } CSS: .noscript{background-color: red; color: white; font-size: 24px; ... } .noscript{background-color: red; color: white; font-size: 24px; ... }
  • js: const noscript = document.querySelector('.noscript').style.display="none"; js: const noscript = document.querySelector('.noscript').style.display="none";

try this css试试这个 css

.noscript {
   background: red;
   top: 100px; 
   color: #fff;
   padding: 10px;
   text-align: center;
   position: relative;
   z-index: 3;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM