当前位置: 代码迷 >> Web前端 >> iframe 里页面超时 跳转登录页有关问题
  详细解决方案

iframe 里页面超时 跳转登录页有关问题

热度:716   发布时间:2012-11-25 11:44:31.0
iframe 里页面超时 跳转登录页问题

ie 中为 frames["id"]其他为document.getElementById("id").contentWindow

contentWindow 属性是指指定的frame或者iframe所在的window对象

在IE中iframe或者frame的contentWindow属性 可以省略,但在Firefox中如果要对iframe对象进行编辑则

必须指定contentWindow属性。

function?EnableEdit()
{
??????var?editor;
??????editor?=?document.getElementById("HtmlEdit").contentWindow;
???//?针 对IE浏览器,?make?it?editable
??????editor.document.designMode?=?'On';
??????editor.document.contentEditable?=?true;
???//?For?compatible?with?FireFox,?it?should?open?and?write?something?to?make?it?work
editor.document.open();
editor.document.writeln('<html><head>');
editor.document.writeln('<style>body?{background:?white;font-size:9pt;margin:?2px;?padding:?0px;}</style>');
editor.document.writeln('</head><body></body></html>');
editor.document.close();

}

<iframe???ID="HtmlEdit"?MARGINHEIGHT="1"?MARGINWIDTH="1"?width="100%"?height="312">
</iframe>

<html>
<body>
<script>
var?ifr?=?document.createElement("iframe");
document.body.appendChild(ifr);
var?ifrdoc?=?ifr.contentWindow.document;
var?s?=?fixingHTB.innerHTML;???// 进入可编辑模式前存好
ifrdoc.designMode?=?"on";?????//文档进入可编辑模式
ifrdoc.open();????????????????????????// 打开流
ifrdoc.write(s);?
ifrdoc.close();????????????????????????//关闭流
ifrdoc.designMode?="off";?????// 文档进入非可编辑模式
</script>
</body>
</html>

http://bei123wang.blog.163.com/blog/static/23175492009101710500739/

以上是引用网易帅哥的一篇文章

其实在昨天也发现自己的一个问题:

iframe 里头的页面超时时转向登录页? 那么框架外的页面 无法跟着返回到登录页?

当时就是没有太在意这个属性而想破头,原来 有一个办法可以用

iframe.contentWindow.location.href

?

if(iframe.contentWindow.location.href.toLowerCase().indexOf("login")!=-1){//如果超时auth/login.jsp
??? ??? ??? ??? ?window.alert("登录超时!");
??? ??? ??? ??? ?top.location.href = obj.contentWindow.location.href;
}

这样式就可以把最外层的跳转到 首页登录了

  相关解决方案