Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

window.location.href 2

Status
Not open for further replies.

link9

Programmer
Nov 28, 2000
3,387
US
Can someone please give me a tip on how to make a button act like a link???

I use
Code:
onClick="window.location.href('myPage.htm')"
, but it's flaky at best. Seems to only work in IE 5.5...

And another thing... Netscape doesn't understand an input type of button???
<input type=button value=&quot;Back to Main&quot; onClick=&quot;window.location.href('myPage.htm')>

This won't even show up in NS 4.7 --

If anyone could give me some pointers, I'd appreciate it.

:)
Paul Prewett
 
Hi Paul,

You need to create a function for that, you can't just do onClick=&quot;window.location.href...&quot; cuz Netscape will think that window.location.href is function. To fix that problem, simple add a function in the onClick event, for example:

<script>
function jumpto(url) {
window.location.href=url
}
</script>
...
<input type=button value=&quot;Back to Main&quot; onClick=&quot;javascript:jumpto('myPage.htm')&quot;>

hope this helps,
Chiu Chan
cchan@gefmus.com
 
Thanks, Chiu --

just what the doctor ordered. :)
 
For anyone reading this thread, using a javascript function such as the one above did not function properly in IE 5.0 --

The one that jaredn suggested does, in fact, work -- thanks
 
I think jaredn hit the nail on the head. Your original button tag was:
Code:
<input type=button value=&quot;Back to Main&quot; onClick=&quot;window.location.href('myPage.htm')>
Change the window's location by saying:
Code:
window.location='myPage.html';
and not
Code:
window.location.href('myPage.html');
This is because window.location.href is only a property, not a function.

Also, your button tag's onClick attribute lacked a closing quote, which might have caused Nutscape not to display it.

Another thing, and I am probably beating a dead dog, but I think window.location.href is intended to be used when you want to obtain a string containing the window's URL. When you want to actually set the window's location, just use window.location. This may be why PepperPepsi's function didn't work properly in Internet Exploder 5.0.

-Petey
 
Yes, it works properly now, and just as a note, as Jared suggested up there, you don't even have to use the window. qualifier... just a simple &quot;location='main.htm'&quot; works great in both browsers...

Thanks for all the input, everyone. :)
paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top