Moving back webpages with Javascript

限于喜欢 提交于 2019-12-13 04:45:37

问题


Ok this is the issue. I am working in a popup. We go from Page 1 to Page 2. Page 2 has frames set up on it. I know it's bad but it was not my decisions. Now on Page 2 in one frame we continue onto Page 3. If I click the back button on Page 2 with javascript history.go(-1) we can get to Page 1. But if the user goes from Page 2 to Page 3 then back to Page 2 a user can not simple go back to Page 1 unless the javascript is history.go(-3). Is there a way I can tell where I am coming from so I can determine which go to use?

FYI URLRefferrer does not work but it only gives me the page holding all the frames. Any suggestions welcomed.


回答1:


An easy way is to link to the page you want directly instead of using history.go. Alternatively, you can try to use parent.history.go(-1).

A third thing you may try, if you have complete control over all the links in the inner frame is to always use location.replace from the inner frame, which will not add an entry into the history, something like the following script

$(function() {
    $('a').click(function(e) {
        e.preventDefault();
        location.replace(this.href);
    });
});


来源:https://stackoverflow.com/questions/9738384/moving-back-webpages-with-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!