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? Quote Link to comment 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 Quote Link to comment 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> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.