![]() |
|
|||||||
| SEO Blog | Register | Rules / FAQ | Members List | Social Groups | Calendar | Search | Today's Posts | Mark Forums Read |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
||||
|
help wanted: detecting http and https in javascript
I would like to implement this pseudo code in javascript, can anyone give me a hand please?
if url is secure then document.write secure-something else document.write non-secure something end if Thanks
__________________
Find your company listing on Manta.com and claim it for free - upload a logo, add detailed info, contact info and (seo friendly) links
|
|
||||
|
if (location.protocol=='https:') yadayada ?????
You may have to do a substr() thingie, cuz I dunno if the location.protocol string EQUALS or CONTAINS https......
__________________
|
|
||||
|
You're too quick Wit! This code, I think, will do it nicely:
Code:
var loc = document.location.href;
if(loc.indexOf("http")>-1){
document.write('Insecure');
}
if(loc.indexOf("https")>-1){
document.write('Secure');
}
__________________
eKstreme.com - Are your keywords buzzing? Blog of science - learn something new today! |
|
||||
|
Thanks for your help guys. I was using it to display the google analytics tracking code which was stored in a global footer include file. The problem is that it would show secure errors when going into https. I don't want to use 2 footer files, so this seems like the best answer:
Code:
<script type="text/javascript">
document.write( '<scr'+'ipt type="text/javascript" src="' );
if( document.location.toString().indexOf( 'https://' ) != -1 ) {
document.write( 'https://ssl' );
} else {
document.write( 'http://www' );
}
document.write( '.google-analytics.com/urchin.js"><\/scr'+'ipt>' );
</script>
<script type="text/javascript">
_uacct = "UA-XXXXXX-X";
urchinTracker();
</script>
__________________
Find your company listing on Manta.com and claim it for free - upload a logo, add detailed info, contact info and (seo friendly) links
|
![]() |
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|