Reputation: 7739
I want to redirect a user where one of condition is true, but I cannot easy write header('Location : something');
, because in my case headers have already been sent (HTML content has been displayed). I know that if user has enabled JavaScript I can write something like that :
<script type="text/javascript">
document.location.href = "http://google.pl";
</script>
But I want to redirect every users, include that which haven't gov JS enabled. I add that this situation is in the <body>
section of document. Is there any way to do that ? I'm asking for every solutions, they must be not for PHP.
PS I read that article, but I think that it cannot help me.
Upvotes: 0
Views: 83
Reputation: 7739
I solved it by cleaning output buffer using ob_end_clean();
function and then use PHP header();
. Of course on the start of the document I have written ob_start();
and on the end ob_end_flush();
. You can read more about output buffering here.
Upvotes: 0
Reputation: 6938
That isn't possible, i think so. but you can implement a message for the browser says to the user that he/she should activate javascript.
<noscript>
You can browse this site without having JavaScript enabled,
but to experience the full benefits of the site, please enable JavaScript.
</noscript>
But you can move forward with the php solution itself.
Add
ob_start()
at the start of the php page and then use
header('Location : something');
I hope help you.
Upvotes: 1
Reputation: 610
Instead of redirecting non-Javascript users Redirect Javascript Users
first give the user the page should be redirected if the user disabled the javascript.
there you write the javascript to redirect the user to the page if the user enabled the javascript, so if the user enabled the javascript then he will be redirected to the correct page but if he disabled the javascript the script not works and he stays in the page which actually should be redirected... hope this useful....
Upvotes: 0
Reputation: 68476
Make use of <noscript>
tag.
Something like this
<noscript>
<meta http-equiv="refresh" content="0; url=http://example.com/somepage.html" />
</noscript>
Upvotes: 3