Jump to content

help for school project


anthonydamasco

Recommended Posts

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

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.