Forum Moderators: open

Message Too Old, No Replies

issue with document.location on FireFox

document.location does not work on FireFox

         

mindshare

2:55 pm on Apr 29, 2005 (gmt 0)

10+ Year Member



I have the follownig code to test our applications for changing the URL on a web page using document.location. When changing the location, the page should jump to the name tag defined in the page.

The code works great on IE without any problem however in FireFox I get a blank page. I look at the source code and it has all of the code for the page however the page does not get displayed unless I hit the refresh button.

Here is the code. Can someone help me?

<?php
$changeURL = $_POST['changeURL'];
if ($changeURL == 1)
{
echo <<<EOF
<SCRIPT TYPE="text/javascript">
window.location = window.location.href+'#uploadSection';
</SCRIPT>
EOF;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>InterChange: Administrative Upload</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form name="testAnchor" method="post" action="testAnchor.php" enctype="multipart/form-data">
<input type="hidden" name="changeURL" value=1>
<input type="button" name="Test" value="Test" onClick="submit();return false;">
<input type="checkbox" name="TestCheckBox">
<a name="#uploadSection"></a>
</form>
</body>
</html>

ajkimoto

3:49 pm on Apr 29, 2005 (gmt 0)

10+ Year Member



mindshare,

I see several things wrong with the code.

1. The <a name=""></a> link should not have the '#' sign in it. The pound sign is used in the link referencing the internal link.

so you should have:

<a href="#myinternallink>Link Me!</a>

<a name="myinternallink></a>

2. It may be that the script is firing before the internal link has loaded. If this isn't happening now, it will happen so someone with a slower connection, especially as you add content to the page. A better way to do this would be to have your php build a js function like this:

//note that you can assign the location to the internal link only without the original window.location
function pager(){
window.location='#myinternallink'
}

and put this in the body tag:

<body onload="pager()">

3. You should have php put the <script>....</script> inside the head. There really should not be anything in the html document above the doctype.

Hope this helps,

ajkimoto

mindshare

6:14 pm on Apr 29, 2005 (gmt 0)

10+ Year Member



ajkimoto
My name is Mehran and I owned a software company. I want to thank you for your detail reply. You helped me a lot. If I need some extra help on projects please email me your contact information.

I updated the code based on your #1 and #3 comments and my code was still not working on FireFox. It was still working on IE.

Your second suggestion solved the problem. You second suggestion stated that the script may get fired before internal link gets loaded into the browser. I moved the portion of the PHP code that set the document.location after the internal link tag. After I moved the code, my code run on FireFox.

I am still not sure why my original code worked on IE and not on FireFox. I guess FireFox has more strictions when it comes to loading a link before defining it. IE has the ability to define the link even I attempt to load them first.

I can proceed with my work now.

thanks a lot.

Here is the final sample code that is working for both IE and FireFox.
<?php
$changeURL = $_POST['changeURL'];
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>InterChange: Administrative Upload</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function pager()
{
window.location='#uploadSection'
}
</script>
</head>
<body>
<form name="testAnchor" method="post" action="testAnchor.php" enctype="multipart/form-data">
<a href="#uploadSection">Click Me</a>
<input type="hidden" name="changeURL" value=1>
<input type="button" name="Test" value="Test" onClick="submit();return false;">
<input type="checkbox" name="TestCheckBox">
<a name='uploadSection'></a>
<?php
if ($changeURL == 1)
{
echo <<<EOF
<SCRIPT TYPE="text/javascript">
alert ("not hello");
window.location = '#uploadSection';
</SCRIPT>
EOF;
}
?>
</form>
</body>
</html>