Well, this was one of the latest issue encountered by me while redirecting to a php page in a php file using php header() function in Internet Explorer.
Problem Description:
header("Location: abc.php?a=b#area"); where area is an anchor link in the html generated by php file abc.php like this
<a name="area" id="area"></a>
The above header function should take to the page abc.php with the current view of the screen on "area" link.
It did so in all major browsers except in Internet Explorer.
So, the solution for the problem was needed to make it browser compatible. After searching and trying different solutions, I adopted the following solution.
Problem Solution:
Here, I will not use the # symbol in the redirection link as it is not a good practice as described in a document on wikepedia----"Clients are not supposed to send URI-fragments to servers when they retrieve a document, and without help from a local application fragments do not participate in HTTP redirections".
The new header function is: header("Location: abc.php?a=b&link=area");
In abc.php, just check if $_GET['link'] is set to area. If it is, then just use this javascript (use jquery function to scroll it to the area link; don't forget to include jquery.min.js).
<?php
if(isset($_GET['link']) && $_GET['link'] == "area")
{
echo '<script type="text/javascript">
$(document).ready(function(){
$(document).scrollTop( $("#area").offset().top );
}); </script>';
}
?>
Thanks for reading this post. Hope you may have got the solution if you have this type of problem.
Problem Description:
header("Location: abc.php?a=b#area"); where area is an anchor link in the html generated by php file abc.php like this
<a name="area" id="area"></a>
The above header function should take to the page abc.php with the current view of the screen on "area" link.
It did so in all major browsers except in Internet Explorer.
So, the solution for the problem was needed to make it browser compatible. After searching and trying different solutions, I adopted the following solution.
Problem Solution:
Here, I will not use the # symbol in the redirection link as it is not a good practice as described in a document on wikepedia----"Clients are not supposed to send URI-fragments to servers when they retrieve a document, and without help from a local application fragments do not participate in HTTP redirections".
The new header function is: header("Location: abc.php?a=b&link=area");
In abc.php, just check if $_GET['link'] is set to area. If it is, then just use this javascript (use jquery function to scroll it to the area link; don't forget to include jquery.min.js).
<?php
if(isset($_GET['link']) && $_GET['link'] == "area")
{
echo '<script type="text/javascript">
$(document).ready(function(){
$(document).scrollTop( $("#area").offset().top );
}); </script>';
}
?>
Thanks for reading this post. Hope you may have got the solution if you have this type of problem.
No comments:
Post a Comment