...

View Full Version : I need help with simple Script



th4shmetal
12-12-2007, 06:57 PM
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?

Arty Effem
12-12-2007, 07:21 PM
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?

This involves reading and if necessary writing to the window.location.href property.
The only real complication here is that a direct comparison using == or != is inadequate, because the URL will contain other characters like 'http://'.
The easiest solution for you will be to use the String.indexOf function.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum