使用JavaScript移回网页 [英] Moving back webpages with Javascript

查看:80
本文介绍了使用JavaScript移回网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好,这是问题所在。我正在弹出窗口中工作。我们从第1页转到第2页。第2页上设置了框架。我知道这很糟糕,但这不是我的决定。现在,在第2页的一帧中,我们继续第3页。如果我使用javascript history.go(-1)单击第2页上的后退按钮,则可以转到第1页。但是,如果用户从第2页转到第3页,则返回第2页,除非javascript是history.go(-3),否则用户无法简单地返回第1页。

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不起作用,但它只给我保存所有内容的页面,有什么办法可以告诉我我来自哪里?框架。欢迎任何建议。

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

推荐答案

一种简单的方法是直接链接到您想要的页面,而不是使用 history.go 。或者,您可以尝试使用 parent.history.go(-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).

第三件事尝试一下,如果您完全控制了内部框架中的所有链接,则始终使用内部框架中的 location.replace ,这不会在历史记录中添加条目,类似于以下脚本

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);
    });
});

这篇关于使用JavaScript移回网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆