Click to See Complete Forum and Search --> : JavaScript Sniffer Question


jennAshton
09-11-2003, 05:19 PM
Right now I have a JavaScript to sniff out which brwoser my users are using. By useing document.write to write out the css call. Is it possible to sniff out what protocols they're using as well. This way when people trying to access https of my site document.write will write out the https css call.

Thank you.

pyro
09-11-2003, 05:40 PM
Take a look at http://www.infinitypages.com/research/location.htm

jennAshton
09-11-2003, 05:56 PM
Wow, it worked on most of the browsers. I am very impressed.

Thanks a ton!

jennAshton
09-11-2003, 06:34 PM
The script works great, however I am already using an external js call to my browser sniffer and css.

<script language="JavaScript" src="http://www.mysite.com/css.js" type="text/javascript"></script>


I have two or three sites that's pointing to the same css.js call (Sorry, I am lazy, I don't want to make three different updates if I can just make one. Plus, I don't get that much traffic so server resources won't be that bad).

I was hoping I can utilize your script to add the +url.protocol+ part into the source call of the js. So, when someone visits https://www.mysite.com or https://www.myothersite.com there won't be a SSL warning of a non-secure call. So, according to the users protocol he or she will either get http or https and then the server path to the JavaScript.

Hope that makes sense...

:rolleyes: :rolleyes:

pyro
09-11-2003, 09:18 PM
You can use the same script to detect the host (www.whatever.com) It is window.location.hostname, or url.hostname in the script that I linked to.

jennAshton
09-12-2003, 12:03 PM
yes, but I cannot do a document.write('<script language="JavaScript" src="'+url.protocol+' // '+url.host+' /css.js" type="text/javascript"></script>');

the script will be written out as text not a script call. Unless I'm missing something. Even if I use character entities it will only print out the script as text.

Btw, thanks for being so paitent with me Pyro.

pyro
09-12-2003, 12:12 PM
Try it like this:

<script type="text/javascript">
document.write('<script type="text/javascript" src="'+url.protocol+'://'+url.host+'/css.js" type="text/javascript"><\/script>');
</script>