Reputation: 2388
I am on a home page and my javascript is enabled. Now what I did, I disabled the javascript and refresh the home.php
page then the page is redirecting on javascript-disabled.php
page because I added the meta tag with URL. There is no issue till here.
My issue is,
I am on javascript-disabled.php
and I enable the javascript and refresh the page but it's not redirecting on the previous page.
This is my URL when javascript is disabled.
http://localhost/example/javascript-disable.php
After enabling the javascript and refresh the page
I got this URL http://localhost/example/undefined
I added
<script type="text/javascript">
window.location.href = window.history.back();
</script>
Home.php
<!DOCTYPE html>
<html>
<head>
<title>home</title>
<noscript><meta http-equiv="refresh" content="0; url=javascript-disable.php" /></noscript>
</head>
<body>
<div>
<!--content her-->
hi
</div>
</body>
</html>
Javascript-disable.php
<!DOCTYPE html>
<html>
<head>
<title>Javascrit disable</title>
</head>
<body>
<div>
<h2>Javascript is disabled.</h2>
<p>Please enable javascript and refersh the page.</p>
<p>To unable to javascript click <a href="#" target="_blank">here</a></p>
</div>
<script type="text/javascript">
</script>
<script type="text/javascript">
window.location.href = window.history.back();
</script>
</body>
</html>
Upvotes: 2
Views: 300
Reputation: 2388
Finally, I found my answer, I don't know it's best or not. Please suggest it's secure or not.
What I did, I added below code on the each page
session_start();
$_SESSION['url'] = $_SERVER['REQUEST_URI'];//It will store the page name
and the javascript-disabled.php page I added in the top
session_start();
$url = $_SESSION['url']; // holds url for last page visited.
At the bottom before closing body tag, I added
<script type="text/javascript">
var previous_page= '<?php echo $url; ?>';
window.location.href = previous_page;
</script>
and It's working perfectly.
Upvotes: 1