You are viewing this forum as a guest. Login to an existing account, or create a new account, to reply to topics and to create new topics.
Hi,
I have stats code I need at the bottom of my footer. It works fine in the footer but there's two available versions, one for http and one for https pages. I need to use perl or something to say "if page is http:, then use this code (code is enclosed in <script> </script>, and if page is https:, then use this other code (also enclosed in <script> </script> tags.
Anyone know if this is even possible in the cart (using scripting within the footer)?
James...
Offline
There are probably more elegant solutions, but you could use javascript as follows the call is for an external script:
<script type="text/javascript"> if (window.location.protocol !="https:") { document.write('<script type="text/javascript" src="url_to_non_https_script"><\/script>') } else { document.write('<script type="text/javascript" src="url_to_https_version"><\/script>') } </script>
Offline
Ed, here's the https: version of the code:
<script type="text/javascript">
var page_name = '';
var invisible = '';
function sE(){return true;}window.onError=sE;
var ui='gsusa';var rn=Math.random();var base=top.document;
var qry=ui+':3::'+escape(base.referrer)+'::'+screen.width
+'x'+screen.height+'::'+screen.colorDepth+'::'+escape(page_name)
+'::'+invisible+'::'+rn+'::'+escape(base.URL);
document.write('<a href="http://www.statsite.com/stats/'+ui+'.htm" ');
document.write('target="new"><img src="https://www.statsite.com/count.pl?');
document.write(qry+'" border="0" alt="invisible hit counter"/><\/a>');
</script><noscript><a href="http://www.statsite.com">
<img src="https://www.statsite.com/3/gsusa.gif"
border="0" alt="invisible hit counter"></a></noscript>
the non-https version is mostly the same.
Would putting all the code after the opening and closing script tags into a .js file that is called work?
Thanks!
James...
Offline
Ed, I added it and it's just printing the code as if its text:
</table>
<script type="text/javascript">
if (window.location.protocol !="https:") {
document.write('<script type="text/javascript" src="http://www.grenvilleusa.com/webstat-non-secure.js"><\/script>')
}
else {
document.write('<script type="text/javascript" src="http://www.grenvilleusa.com/webstat-secure.js"><\/script>')
}
</script>
</BODY>
</HTML>
this is what is found when viewing source on the site. All I did was add it to the bottom of the ste_layout element - am I suppose to add it somewhere else?
James...
Offline
Ed, shouldn't it if statement cause only one of the two lines below be written in the final html visible to the end user?
<script type="text/javascript">
if (window.location.protocol !="https:") {
document.write('')
}
else {
document.write('')
}
</script>
Either the red or blue text is what is only on the final rendered page?
James...
Offline
I PM'd you the URL for http & https versions of a test page. I increased the border size of the tracking image and added text to identify each version. I think I misunderstood and thought that the script was rendered as text on the page - it will show up in the html.
Offline
Ed,
I pm'd you - but for others who might be following this thread.
Shouldn't the actual web page (when clicking on view source) show only the one <script> tag that calls one version or the other and not document_write, etc...
Regards,
James...
Offline
Hey James, short answer: that's normal to see the script in the source rather than the output. If you 'view source' from some of the old netscape browsers you would see what was written by the document.write instead.
Offline