anon
anon

Reputation:

Create a <noscript> element with content fails on IE7 and IE8 (jQuery)

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.

Upvotes: 1

Views: 5694

Answers (3)

Reporter
Reporter

Reputation: 3948

I tried following simple HTML code:

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

Then I did analyse this with IE8 (in IE7 mode) and his integrated code insprector. Apparently the IE7 checks are script allowed. If so he declared it as empty. And empty tags will be ignored. Unfortunatly I could not try that with disabled script option, because only the Systemadministrator can change the settings (here at my work). What I can assure you, the noscript does exists. If you add

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

after the creation, the result will be 1.

Upvotes: 0

Dennis
Dennis

Reputation: 14465

Just an idea: You could try giving your noscript tag an ID, and then try to use native js. for example:

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

I would claim that if it does not work with native js, it will not work with any library (feel free to correct me on this one).

Upvotes: 1

Jan Hančič
Jan Hančič

Reputation: 53931

Regardless of the tracking code, what you are doing (or are required to do) makes no sense!

Why? There are two cases possible here:

  • user has JavaScript enabled in which case the NOSCRIPT get's inserted into the DOM but is ignored by the browser (does nothing)
  • user does not have JavaScript enabled, NOSCRIPT does not get inserted and does not "execute"

The end result of both cases is that nothing actually happens.

Upvotes: 7

Related Questions