1

I've seen several threads about reading contents, but nothing on writing to noscript.

$('body').append('<noscript><div></div></noscript>');

In Chrome and IE9 I get a noscript-element with a empty div inside like I expect, but in IE7 and IE8 I just get a empty noscript-element without the div inside.

Example: http://jsfiddle.net/cEMNS/

Is there a way to add HTML inside the noscript-tag that works in all browsers? What I need is to add some tracking code into a noscript-element at the end of the page, but the info I need isn't available until after document ready.

Edit: I'm getting a lot of comments on "why". It's some poorly done tracking library that requires this. We don't have access to the code to change it. Regardless, I find it interesting that it works in some browsers and not in others since jQuery was supposed to work equally in all browsers. Is it simply a bug?

Edit2: (2 years later) Adding a noscript on the browser doesn't make sense, I know. My only excuse not the question the task I had was because of lack of sleep, like everyone else in the project. But my rationale was that jQuery should behave the same on all browsers and someone might want to do this on the server.

4

3 回答 3

7

无论跟踪代码如何,您正在做的(或被要求做的)都是没有意义的!

为什么?这里可能有两种情况:

  • 用户启用了 JavaScript,在这种情况下 NOSCRIPT get 被插入到 DOM 中,但被浏览器忽略(什么都不做)
  • 用户没有启用 JavaScript,没有插入 NOSCRIPT 也没有“执行”

这两种情况的最终结果是实际上什么都没有发生。

于 2012-04-04T13:09:08.140 回答
1

只是一个想法:您可以尝试为您的noscript标签提供一个 ID,然后尝试使用本机 js。例如:

$('body').append('<noscript id="myTestNoScript"></noscript>');
document.getElementById('myTestNoScript').innerHTML = '<div></div>';

我会声称,如果它不适用于本机 js,它将不适用于任何库(请随时纠正我的这个问题)。

于 2012-04-04T13:15:36.810 回答
0

我尝试了以下简单的 HTML 代码:

 <html>
    <body>
        <noscript>I'm a noscript tag.</noscript> 
    </body>
</html>

然后我确实用 IE8(在 IE7 模式下)和他的集成代码检查器对此进行了分析。显然 IE7 检查是脚本允许的。如果是这样,他宣布它为空。空标签将被忽略。不幸的是,我无法尝试禁用脚本选项,因为只有系统管理员可以更改设置(在我的工作中)。我可以向你保证,noscript 确实存在。如果你添加

alert($('noscript').size());

创建后,结果将为 1。

于 2012-04-04T13:33:48.487 回答