Forum Moderators: open

Message Too Old, No Replies

Dynamically choosing which .js file to include

         

CernyM

5:32 pm on Dec 2, 2005 (gmt 0)

10+ Year Member



In my master page header template, I'd like to be able to choose one of two external javascript files to include.

The first file, http://www.example.com/script.js would be included if I was not on a secure (SSL) page.

The second file, [ssl.example.com...] would be included if I was on a secure (SSL) page.

Is this possible?

Sathallrin

7:37 pm on Dec 2, 2005 (gmt 0)

10+ Year Member



Do something like this:
<script language="JavaScript" type="text/javascript">
if(location.href.indexOf('https')!=-1) {
document.write('<scr'+'ipt language="JavaScript" type="text/javascript" src="https://ssl.example.com/script.js"><\/scr'+'ipt>');
}
else {
document.write('<scr'+'ipt language="JavaScript" type="text/javascript" src="http://www.example.com/script.js"><\/scr'+'ipt>');
}
</script>

kaled

7:56 pm on Dec 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Assuming the scripts perform a similar function, why not use the document.location.protocol string to decide what to do in the script.

Kaled.

CernyM

8:20 pm on Dec 2, 2005 (gmt 0)

10+ Year Member




Assuming the scripts perform a similar function, why not use the document.location.protocol string to decide what to do in the script.

They aren't my scripts - they are tracking scripts hosted by a third-party.