[英]How to go back to the previous page skipping inner page navigation with href=“#id”. Using javasctip
I'm new to javascript and web developments. 我是javascript和网络开发的新手。 I'm looking for a way of going back to previous page from current page skipping all the inner page navigation.
我正在寻找一种跳过当前所有内部页面导航,从当前页面返回上一页的方法。
I know that back funtionality can be implemented by window.history.back(); 我知道可以通过window.history.back();实现反向功能。 or window.history.go(-1);
或window.history.go(-1);
but this will only send me back to the last inner page navigation, if I have done any. 但这只会将我带回到上一个内页导航(如果我做了任何操作)。
Example 例
Let's say I have come from www.firstpage.com and currently I'm in www.secondpage.com. 假设我来自www.firstpage.com,目前我在www.secondpage.com。 And there are links provided by that page to navigate inside that page.
该页面提供了一些链接,可以在该页面内导航。 Let's say I have navigate through following path.
假设我已经通过以下路径导航。
www.secondpage.com#id1 --> www.secondpage.com#id2 www.secondpage.com#id1-> www.secondpage.com#id2
So my current URL is www.secondpage.com#id2, now I want to go back to www.firstpage.com. 所以我当前的URL是www.secondpage.com#id2,现在我想回到www.firstpage.com。 Back function will only take me to the www.secondpage.com#id1
后退功能只会将我带到www.secondpage.com#id1
After some research on internet I realize there is not straight way to do this. 在对互联网进行一些研究之后,我意识到没有直接的方法可以做到这一点。 So I implemented my own method.
所以我实现了自己的方法。 When the back option is clicked I called the "goBackContinue" method which continuously call "goBack" in 50mils interval, which call window.history.back();.
当单击后退选项时,我调用了“ goBackContinue”方法,该方法以50mils的间隔连续调用“ goBack”,该方法调用window.history.back();。 So it will back the user continuously till he get out of the page.
因此它将持续支持用户,直到他退出页面。 Following is the code
以下是代码
<!DOCTYPE html> <html> <body> <button onclick="goBackContinue()">Go Back</button> <script> function goBackContinue(){ var myVar = setInterval(function(){ goBack() }, 50); } function goBack() { window.history.back(); } </script> </body> </html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.