简体   繁体   English

有关javascript history.go的简单问题

[英]Simple question about javascript history.go

I have a classifieds website. 我有一个分类广告网站。 In every classified, there is a back link which simply takes the browser back one step. 在每个分类中,都有一个反向链接,该链接仅会使浏览器后退一步。 This is because when users search classifieds, and click on one to view it, they can easily go back with a link also (instead of only the browser back button). 这是因为,当用户搜索分类并单击一个分类时,他们也可以轻松地返回一个链接(而不仅仅是浏览器后退按钮)。

Here is the problem, if the classified is entered directly into the adress bar of a browser, or if somebody bookmarked a classified, then this back-link would take them someplace else... 这是问题所在,如果将分类广告直接输入到浏览器的地址栏中,或者如果有人将分类广告加为书签,则此反向链接会将它们带到其他地方...

Is there any way of making sure that the previous page is a certain page (index.php in my case)? 有什么方法可以确保上一页是某个页面(在我的情况下为index.php)? This way I would only display the back link if the previous page was index.php... 这样,如果上一页是index.php,我只会显示反向链接。

Thanks 谢谢

You can't query history data. 您无法查询history数据。 A slightly better option is to read the Referrer server variable and create your "Back" link to it. 更好的选择是读取Referrer服务器变量并创建指向它的“后退”链接。 It's not very much stronger than history.go() , though. 不过,它并没有比history.go()强很多。 Try using a common index page instead. 尝试改用通用索引页。

Why not just insert a link to index.php directly? 为什么不直接插入指向index.php的链接? That way you have complete control over the target of the link. 这样,您就可以完全控制链接的目标。 No need for JavaScript. 无需JavaScript。

You should track their session within PHP or whatever language you're using in order to have an effective "back" button. 您应该在PHP或您使用的任何语言中跟踪他们的会话,以便获得有效的“后退”按钮。

You could pull the data with document.referrer but that will not always give you the previous page. 您可以使用document.referrer提取数据,但并不总能得到上一页。 Sadly I am not sure of a way to achieve a "Back" button via javascript without using some kind of scripting language to track a user either via cookie or session. 遗憾的是,我不确定是否可以通过JavaScript实现“返回”按钮,而无需使用某种脚本语言通过Cookie或会话来跟踪用户。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM