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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Window.location problem in Firefox

Status
Not open for further replies.

ashaig

Programmer
Apr 9, 2001
26
GB
I'm trying to redirect to a page in same window. Works fine in IE, but not firefox. It's getting to the redirected page because an alert I have there pops up. However when I click on 'OK' the sending page re-opens. Grateful for any suggestions.

Here is the link:
<a href="#" target="_self" onClick="javascript:transfer();">Beurla </a>

and here is the function:
function transfer()
{
var sgPath = window.location.pathname;
var vgPath;
alert(sgPath);
sgPath = sgPath.replace("_gaelic.htm", ".htm");

if (sgPath.lastIndexOf('canan_test') != -1)
{
vgPath = sgPath.replace("canan_test/gaelic_site", "canan_test");
}
else
{
vgPath = sgPath.replace("/gaelic_site/", "/");
}
alert(vgPath);
window.location.href = vgPath ;

}
 
Assuming that vgPath contains the correct value (which I'm guessing it does since you're alerting it's contents right before the location change), then you do not need this part of the code:
Code:
window.location[s].href[/s] =  vgPath ;

Here's a quick example which does work in firefox and IE7, you'll see that the link goes to google instead of tek-tips from the window.location redirect:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<script type="text/javascript"></script>
<style type="text/css"></style>
</head>
<body>

<a href="[URL unfurl="true"]http://www.tek-tips.com"[/URL] onclick="window.location = '[URL unfurl="true"]http://www.google.com';[/URL] return false">click me</a>

</body>
</html>

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
Kaht,

I took out the window.location.href, but nothing doing. I'm wondering if the onclick might be the issue. I know that mozilla browsers are more strict than IE so a small error might be causing this.

As I said I get the alert coming up on the new page, but goes no further after the click - just comes back to calling page.
 
Try making these changes:
Code:
<a href="#" onClick="[!]return[/!] transfer();">Beurla </a>

function transfer()
{
    var sgPath = window.location.pathname;
    var vgPath;
    alert(sgPath);
    sgPath = sgPath.replace("_gaelic.htm", ".htm");

    if (sgPath.lastIndexOf('canan_test') != -1)
    {
        vgPath = sgPath.replace("canan_test/gaelic_site", "canan_test");
    }
    else
    {
        vgPath = sgPath.replace("/gaelic_site/", "/");
    }
    alert(vgPath);
    window.location =  vgPath ;
    [!]return false;[/!]
}

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
Kaht,

that did the job! Thanks a lot!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top