anthonydamasco Posted December 12, 2007 Share Posted December 12, 2007 Hello, I am taking a college course for javascript and I'm stuck on an assignment. I need to write an if/then statement that is declaired by the url in the address bar. If - url in address bar = www.princetonuniversity.com/index.html Then - display <html> home page </html> ELSE If - url in address bar = www.princetonuniversity.com/about.html Then - display <html> about us page </html> Can someone give me an example on how to write this script? Link to comment https://forums.phpfreaks.com/topic/81377-help-for-school-project/ Share on other sites More sharing options...
emehrkay Posted December 12, 2007 Share Posted December 12, 2007 var url = window.location; you should be able to do the rest Link to comment https://forums.phpfreaks.com/topic/81377-help-for-school-project/#findComment-412988 Share on other sites More sharing options...
phpQuestioner Posted December 12, 2007 Share Posted December 12, 2007 try this: <script language="javascript"> var local = document.URL; var hpage="http://www.princetonuniversity.com/index.html"; var aupage="http://www.princetonuniversity.com/about.html"; function urlcheck() { if (local == hpage) { document.location.href = hpage; } else if (local == aupage) { document.location.href = aupage; } } window.onload=function() { urlcheck(); } </script> I think, the best way to use the above script is to load it externally; but that is just my opinion. <script type="text/javascript" src="Your-JS-URL.js"></script> Link to comment https://forums.phpfreaks.com/topic/81377-help-for-school-project/#findComment-413153 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.