简体   繁体   中英

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)? This way I would only display the back link if the previous page was index.php...

Thanks

You can't query history data. A slightly better option is to read the Referrer server variable and create your "Back" link to it. It's not very much stronger than history.go() , though. Try using a common index page instead.

Why not just insert a link to index.php directly? That way you have complete control over the target of the link. No need for JavaScript.

You should track their session within PHP or whatever language you're using in order to have an effective "back" button.

You could pull the data with document.referrer but that will not always give you the previous page. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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