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: /
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 ments 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.
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/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 ments 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.
Share Improve this question edited Sep 10, 2014 at 8:41 asked Apr 4, 2012 at 12:25 anonanon 5-
7
Just curious... is there a practical reason to add
noscript
tags via javascript ? o_O – Dennis Commented Apr 4, 2012 at 12:28 - While I do appreciate everyone's personal opinion, I did not write the tracking code I just need to include some info to it that's not available until later. Regardless, I see no reason for this to work in Chrome and IE9 but not in IE7 and IE8. – anon Commented Apr 4, 2012 at 12:32
- @John-Philip the noscript tag will be invoked, if javascript (or for IE, the execution of any script language) is not allowed. It can only contains HTML. In my eyes it makes no sense to append it with Javascript. – Reporter Commented Apr 4, 2012 at 12:44
- @reporter but it is only including elements? It's a div. Yes yes I agree that this should be solved differently, but I didn't write the library nor do we have the code for it. Regardless, I still don't see a reason for this to work in some browsers and not in others. I'd appreciate if you could focus on that instead. – anon Commented Apr 4, 2012 at 12:53
- (2 years later) I've tried deleting this question. For what I was trying to do it doesn't make any sense. The whole team needed sleep badly so I wasn't very clear headed. But my rationale was that if I was running this on the server then jQuery should just work. And that the discrepancy between browsers should be fixed. – anon Commented Sep 10, 2014 at 8:38
3 Answers
Reset to default 7Regardless 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.
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).
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.