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 problem

Status
Not open for further replies.

Microbe

Programmer
Oct 16, 2000
607
AU
Hello,

I am trying to make a page redirect. I can't get window.location.href to work from inside a function. Is this a known issue?????

It works if I don't have it inside the function and I have tested that I am calling the function.

I could have sworn I have done it in the past.

Thanks a lot in advance Steve Davis
hey.you@hahaha.com.au
 
onclick="window.location.href=url"

is that how u use it [soapbox]
sleep is good
 
yes.

I have made a workaround by putting it into frames and going parent.mainFrame.location.href = URL which works, but I still have no idea whay window.location.href to the same URL won't. :( Steve Davis
hey.you@hahaha.com.au
 
I don't know what's the problem of your particular issue, but I always use
[tt]document.location.href=url;[/tt]
and it never fails.
 
the two previous posters probably know more about this than I do, but is the function doing anything else? I'm guessing not if you're redirecting the user. why don't you post some code?
 
Thanks for the suggestion, but I have already tested by whittling the function down to one line, just the .href redirection with no joy.

As I say, the line works by itself, if I then add the function around it, it fails.

The weird part is that it doesn't break the script. If I put an alert after the .href, it hits the alert. It just doesn't do the redirection.

Steve Davis
hey.you@hahaha.com.au

Me? I can't even spell ASP!
 
I have the same problem. I have used this same exact script in another page an it works fine. But when I reused it on another page, nothing happens.

The an onClick event triggers the SimuSearch() which check the value of the text box. If there is a match, then the page should change.


<script>
<!--//

function GO2URL() {
alert(&quot;Going....&quot;)
window.location.href=&quot;search4.html&quot;
return false;
}

function SimuSearch() {

var txt = document.theForm.text.value
txt = txt.toLowerCase()
alert(&quot;\&quot;&quot; + txt + &quot;\&quot;&quot;)
switch (txt) {

case &quot;&quot; :
{
//do nothing if text box is blank.
break;
}

case &quot;alcohol and advertising and children&quot; :
{
//alert(&quot;Expected&quot;)
GO2URL();
break;
}

default :
{
//alert(&quot;Expected w/ Twist&quot;)
txt = txt.split(&quot; &quot;)
//alert(txt.length)
if (txt.length > 2)
{
//alert(txt[0].substring(0,4) + &quot;\n&quot; + txt[2].substring(0,4) + &quot;\n&quot; + txt[4].substring(0,4))
if ((txt[0].substring(0,4) == &quot;alco&quot;) && (txt[1].substring(0,4) == &quot;adve&quot;) && (txt[2].substring(0,4) == &quot;chil&quot;))
{
GO2URL();
}
}
else
{
document.theForm.text.value = &quot;&quot;
alert(&quot;Please enter the exact phrase \&quot;alcohol and advertising and children\&quot; into the text box&quot;)
}
}
}
}
//-->
</script>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top