iframe返回javascript - 避免主页返回 [英] iframe Back with javascript - avoid main page go back

查看:390
本文介绍了iframe返回javascript - 避免主页返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 iframe ,并且我有一个后退按钮来运行这个javascript代码(当用户点击后退按钮时):

  document.getElementById(myframe)。contentWindow.history.go(-1); //返回

这很好,但如果框架中没有前一页,主页面会回去。



如何避免这种情况?我只想要iframe回去,如果没有以前的页面,就不要做任何事情。



编辑:这是我的代码。 (@ jsfiddle)

保持跟踪这样的更改:

 <脚本> 
window.iFrameChanges = -1; //在第一页加载时将增加到0
< / script>

< iframe onLoad =window.iFrameChanges + = 1; SRC = ... >< / iframe中>

递减 window.iFrameChanges 值在历史上回去



这样你就可以知道历史的长度了

I'm using an iframe, and I have a back button which runs this javascript code (when user clicks on back button):

document.getElementById("myframe").contentWindow.history.go(-1); // back

This works fine, but If there is no previous page in the frame, main page will go back.

How to avoid this? I want just iframe to go back, and if there is no previous page, simply do nothing.

EDIT: This is my code. (@ jsfiddle)

解决方案

Keep track of changes like this:

<script>
    window.iFrameChanges = -1; //will get incremented to 0 on first page load
</script>

<iframe onLoad="window.iFrameChanges+=1;" src="..."></iframe>

And the decrement the window.iFrameChanges value on history go back

This way you can know the "length" of history

这篇关于iframe返回javascript - 避免主页返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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