浏览器返回在页面本身之前作用于嵌套的 iframe - 有没有办法避免它? [英] browser back acts on nested iframe before the page itself - is there a way to avoid it?

查看:8
本文介绍了浏览器返回在页面本身之前作用于嵌套的 iframe - 有没有办法避免它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面,其中包含由一些 ajax 和大量 javascript 加载的动态数据.

I have a page with dynamic data loaded by some ajax and lots of javascript.

页面包含一个列表,用户可以从中进行选择,每个选定的值都会向页面加载新数据.

the page contains a list from which the user can choose and each selected value loads new data to the page.

这些数据项之一是提供给 iframe 的 url.

One of these data items is a url provided to an iframe.

我使用 jQuery BBQ: Back Button &查询库来模拟浏览器返回的行为.

I use jQuery BBQ: Back Button & Query Library to simulate the browser-back behavior.

除了当我第一次单击后退按钮时 iframe 返回到以前的位置,然后我需要再次单击返回以使页面返回的事实之外,一切都运行良好.

All works well besides the fact that when i click the back button for the first time the iframe goes back to its previous location and then I need to click back again to make the page go back.

有没有办法禁用 iframe 的返回行为?

Is there a way to disable the iframe's back behavior?

推荐答案

我已经找到了我问题的答案,猜测它可能对其他人有用.

I've found the answer to my problem guess it could be useful for others out there.

问题在于我为 iframe 分配新 URL 的方式,我使用了 Jquery,所以它看起来像这样:

The problem was with the way i assigned new URLs to my Iframe, i used Jquery so it looked something like that:

$('#myIFrame').attr('src',newUrl);

当以这种方式分配 URL 时,它会在浏览器的访问 URL 列表中添加一个新条目以返回.
这不是我们想要的行为,所以经过一些谷歌搜索后,我发现您可以为 iframe 对象分配一个新 URL,而无需将其添加到后备列表"中,它看起来像这样:

When assigning the URL in that manner it adds a new entry to the browser's list of visited URLs to go back to.
That wasn't the desired behavior, so after some googling i found that you can assign a new URL to an Iframe object without adding it to the 'back-list', it looks like that:

var frame = $('#myIFrame')[0];  
frame.contentWindow.location.replace(newUrl);

这样我的后退按钮就完全符合预期.

This way my back button behave exactly as expected.

顺便说一句,我从这里得到了我的答案.

希望这对你和我都有帮助.

Hope this was helpful to you as it was to me.

这篇关于浏览器返回在页面本身之前作用于嵌套的 iframe - 有没有办法避免它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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