[英]How to make a custom Back button for jQuery load() content
In one of my php page (Report.php), I am loading its content through jQuery load().在我的 php 页面之一 (Report.php) 中,我正在通过 jQuery load() 加载其内容。 I want to create a "back button" on my php page so that my user can click it to go back pages.
我想在我的 php 页面上创建一个“后退按钮”,以便我的用户可以单击它转到 go 后退页面。 Note - I am not looking for browser back button.
注意- 我不是在寻找浏览器后退按钮。
Here is my php pages -这是我的 php 页 -
report_template.php report_template.php
//This page query my database and creates a content table<br>
//Table content
<a href="#" onclick="fetchReport(<?php echo $row['report_id']; ?>);">Another Report Link</a>
report.php报告.php
<button>Go Back</button> //This button will take user to back (equivalent to window.history.back() )
<div id="rept"> </div>
<script>
jQuery('#rept').load('report_template?id=1');
function fetchReport(id){
jQuery('#rept').load('report_template?id='+id);
}
</script>
I am average level skill in jquery/javascript.我的 jquery/javascript 技能一般。
At the top of every page start session session_start();
在每一页的顶部开始 session
session_start();
and set the current page as a $_SESSION
variable.并将当前页面设置为
$_SESSION
变量。 IE IE
<?php
session_start();
$_SESSION['last_page'] = $_SERVER['PHP_SELF']; // Or whatever you designate it as
Then you can call it in report.php然后就可以在report.php中调用了
<?php
session_start();
<button onClick="window.open(<?= $_SESSION['last_page'] ?>);">Go Back</button> //This button will take user to back (last report page he's seen)
<div id="rept"> </div>
<script>
jQuery('#rept').load('report_template?id=1');
function fetchReport(id){
jQuery('#rept').load('report_template?id='+id);
}
</script>
A slightly simpler, yet less reliable way to do it, is to grab the last page the person was on according to PHP $_SERVER['HTTP_REFERER']
This can also include "off server" pages.一种稍微简单但不太可靠的方法是根据 PHP
$_SERVER['HTTP_REFERER']
获取该人访问的最后一页这也可以包括“关闭服务器”页面。 Also it may better suit your question if the referrer may, in fact, come from "somewhere else" IE:如果推荐人实际上可能来自“其他地方”IE,它也可能更适合您的问题:
<button onClick="window.open(<?= $_SERVER['HTTP_REFERER'] ?>);">Go Back</button>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.