Click to See Complete Forum and Search --> : onClick="location.href ... not always working


Anders
02-14-2003, 04:30 AM
I want to use a link which at the same time

1) opens a new window with a specific URL
2) opens a new URL in the old window

I have tried
<a href="newwindowURL" target="_blank" onClick="location.href('oldwindowURL')">click here</a>

and this works when I try it (IE6), but I keep getting user feedback that for some people only the new window opens with the newwindowURL, but nothing happens at all in the old window.

How can I deal with this? The users use IE just as me, so it doesn't appear to be a browser issue.

Is either onClick not available for some or is location.href not understandable to some? Can I rewrite this with some errorchecking to make it work for all users?

Thanks for any insight, I am a newbie with this (which you probably already have noticed!).

IxxI
02-14-2003, 04:50 AM
I would do it the other way (opening a new window with your onClick command)


<a href="oldwindowURL" onClick="window.open('newwindowURL');">Click me!</a>


Hope this helps.
IxxI

Anders
02-14-2003, 05:19 AM
Thanks IxxI!

But there is another issue, the referrer url (the page where my link is) MUST be sent to the newwindowurl. Will that happen if I put the newwindowurl in the onclick=window.open?

Anders

gil davis
02-14-2003, 05:39 AM
This should get you where you want to go:

<script>
function changeURL() {
location.href="oldwindowURL";
}
</script>
<a href="newwindowURL" target="_blank onClick="setTimeout('changeURL()',100)">click here</a>

Anders
02-14-2003, 07:24 AM
Gil, thank you very much!

This made all the difference. Now it works for the user with the problem. So just a timeout of one second solved it... !?!

gil davis
02-14-2003, 07:34 AM
What I posted should have been 100 mS - not a second (1000 mSec = 1 sec). The value was a guess. It may even work at 0. It gives the browser a bit of time to finish one job before it starts another.