DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/)
-   JavaScript / DHTML / AJAX (http://www.daniweb.com/forums/forum117.html)
-   -   Redirect page function problem with Firefox browser (http://www.daniweb.com/forums/thread122553.html)

tanha May 5th, 2008 9:53 am
Redirect page function problem with Firefox browser
 
Hi everybody,
I am using a java script function which redirect to the page according to the given parameter, and it is working as desired in IE, but I found that it not work with Firefox browsers, so some one plz guide me how it is possible to have the same function which could work on IE and Mozilla firfox.

The function code:


<?php
function reDirect($page)
{
    $s = "<script language = 'javascript'>
    window.navigate('$page');
    </script>";
    return $s;
}

Thanks

~s.o.s~ May 8th, 2008 1:20 pm
Re: Redirect page function problem with Firefox browser
 
There is no
navigate
function for the
window
object. Maybe try something like:
<?php
function reDirect($page)
{
    $s = "<script language = 'javascript'>
    window.location.href = '$page';
    </script>";
    return $s;
}

digital-ether May 10th, 2008 5:05 am
Re: Redirect page function problem with Firefox browser
 
Quote:

Originally Posted by tanha (Post 600016)
Hi everybody,
I am using a java script function which redirect to the page according to the given parameter, and it is working as desired in IE, but I found that it not work with Firefox browsers, so some one plz guide me how it is possible to have the same function which could work on IE and Mozilla firfox.

The function code:


<?php
function reDirect($page)
{
    $s = "<script language = 'javascript'>
    window.navigate('$page');
    </script>";
    return $s;
}

Thanks



Unless there is a specific need for using javascript, you could redirect the browser using HTTP headers.

<?php

function reDirect($page)
{
    header("Location: $page"); // tell the browser to go to the new location..
    die; // die so we can flush http output immediately
}


?>

digital-ether May 10th, 2008 6:49 am
Re: Redirect page function problem with Firefox browser
 
Quote:

Originally Posted by Mohan0704 (Post 604115)
Isn't the die function the same as the exit function? Also, you can put a message to show people that the program is exiting
such as:
exit ('The program is exiting')
and
die ('The program is dying')



I believe they are the same.

The user would never see the message however under normal circumstances.

Its always good to add a bit of HTML explaining whats happening however, and add the JS that will redirect in case the browser fails to do a HTTP redirect.

~s.o.s~ May 10th, 2008 2:01 pm
Re: Redirect page function problem with Firefox browser
 
> You could just use a meta command (like this):

The W3C actually recommends against the use of such tricks for redirection. If Javascript is not a must, Digital Ether's suggestion seems good enough.


All times are GMT -4. The time now is 4:01 am.

Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC