javascript - 如何从禁用 javascript 的页面重定向到上一页?
问题描述
我在主页上,并且我的 javascript 已启用。现在我做了什么,我禁用了javascript并刷新home.php
页面,然后页面重定向javascript-disabled.php
因为我添加了带有 URL 的元标记。到这里为止没有问题。
我的问题是,
我在javascript-disabled.php
了,我启用了 javascript 并刷新了页面,但它没有在上一页上重定向。
这是禁用 javascript 时我的 URL。
http://localhost/example/javascript-disable.php
启用 javascript 并刷新页面后,我得到了这个 URLhttp://localhost/example/undefined
我添加了
<script type="text/javascript">
window.location.href = window.history.back();
</script>
主页.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>
解决方案
最后,我找到了我的答案,我不知道它是否最好。请建议它是否安全。
我做了什么,我在每个页面上添加了以下代码
session_start();
$_SESSION['url'] = $_SERVER['REQUEST_URI'];//It will store the page name
以及我在顶部添加的 javascript-disabled.php 页面
session_start();
$url = $_SESSION['url']; // holds url for last page visited.
在关闭 body 标签之前的底部,我添加了
<script type="text/javascript">
var previous_page= '<?php echo $url; ?>';
window.location.href = previous_page;
</script>
它运行良好。
推荐阅读
- bash - 如何使用 slurm 使用 worker/master 概念在不同节点上运行不同的独立并行作业?
- mysql - 在 Windows 上安装 MySql 8.0 和 Visual C++ Redistributable 疑难解答
- arrays - UserForm 变量范围:将二维数组值从 userform2 传输到 userform1
- arrays - 创建 Swift 数组的最快方法
具有固定计数 - vue.js - 如何将此 src 绑定到 vue js 中的 iFrame?
- excel - VBA代码在引用从B列到D列的一系列单元格时创建文件夹和子文件夹?
- python - 使用从 URL / Postcode 到 NUTS1 映射的文本文件创建 SQLite 数据库
- angular - 子目录上的 Laravel
- r - 如何让这个标签指向最左边的栏?
- java - YAMLBeans - a 的预期数据
但找到的字段:标量