Forum Moderators: open

Message Too Old, No Replies

How to include noscript into js file?

         

toplisek

10:08 am on Dec 2, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I like to place analytic code like:
var stat_site_ids = id || [];
statid.push();
(function() {
var s = document.createElement('script');
s.type = 'text/javascript';
s.async = true;
s.src = '//static.statistics.com/js';
( document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0] ).appendChild( s );
})();
<noscript><p><img alt="Mystat" width="1" height="1" src="//statistics.com/image.gif" /></p></noscript>

How to include this code into JS file as it will not be correct due to <noscript> and other elements?

graeme_p

10:48 am on Dec 2, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You cannot. You could split it and put the script in a JS file and the HTML on the page.

lucy24

7:27 pm on Dec 2, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Even if it were syntactically possible-- which it isn't if you're thinking of a <script src> construct-- there's little point in including
<noscript>
code in an external js file. Who would see it? (Do current browsers load .js files in advance if they've been set to "no scripting"? What a waste, if so.)

Now, you could put the whole package-- script and noscript versions, and any supplemental stuff such as images-- into a single include file, such as an SSI or a php include. But I don't think that is what you're asking.

toplisek

7:53 pm on Dec 3, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I have currently simple changed to HTML. Maybe PHP is better due to other stuff...