Kryptronic Software Support Forum

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.

#1 02-05-2006 22:13:48

wyattea
Member
Registered: 01-07-2006
Posts: 1650

Adding Script To Footer

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

 

#2 02-05-2006 23:40:52

Ed_H
Member
From: Smashachusetts
Registered: 09-12-2003
Posts: 397
Website

Re: Adding Script To Footer

There are probably more elegant solutions, but you could use javascript as follows  the call is for an external script:

Code:

<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

 

#3 02-05-2006 23:50:14

wyattea
Member
Registered: 01-07-2006
Posts: 1650

Re: Adding Script To Footer

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

 

#4 02-06-2006 00:09:16

Ed_H
Member
From: Smashachusetts
Registered: 09-12-2003
Posts: 397
Website

Re: Adding Script To Footer

Hi James - Yes, making them external .js files then calling them per the example above will work.  The <noscript> content is a little trickier....

Offline

 

#5 02-06-2006 00:39:27

wyattea
Member
Registered: 01-07-2006
Posts: 1650

Re: Adding Script To Footer

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

 

#6 02-06-2006 01:06:18

Ed_H
Member
From: Smashachusetts
Registered: 09-12-2003
Posts: 397
Website

Re: Adding Script To Footer

Hmmm.  I tested with the exact script from your post on a ccp ste_layout and it worked.  I'll see if I can duplicate what you're experiencing.  Should work as placed.

Offline

 

#7 02-06-2006 07:35:05

wyattea
Member
Registered: 01-07-2006
Posts: 1650

Re: Adding Script To Footer

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

 

#8 02-06-2006 10:05:45

Ed_H
Member
From: Smashachusetts
Registered: 09-12-2003
Posts: 397
Website

Re: Adding Script To Footer

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

 

#9 02-06-2006 10:49:25

wyattea
Member
Registered: 01-07-2006
Posts: 1650

Re: Adding Script To Footer

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

 

#10 02-06-2006 12:58:20

Ed_H
Member
From: Smashachusetts
Registered: 09-12-2003
Posts: 397
Website

Re: Adding Script To Footer

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

 

Board footer