iframe中的Window.top和top.document(Window.top and top.document in iframe)

编程入门 行业动态 更新时间:2024-10-26 02:27:56
iframe中的Window.top和top.document(Window.top and top.document in iframe)

我有2页,page1.html(mypage)和page2.html(外部),page1.html使用iframe加载page2.html。 page2.html基本上有用户信息,它包含菜单,表格。 下面的代码有一个注销功能

$('#inetLogoutId').click(function(event) { var logoutMsg = "Are you sure you want to log out?"; dialogConfirm(logoutMsg, function() { top.document.location.href = path + "/logout"; }) });

由于Uncaught DOMException: Blocked a frame with origin "https://example.com" from accessing a cross-origin frame.注销无法正常工作Uncaught DOMException: Blocked a frame with origin "https://example.com" from accessing a cross-origin frame. ,如果将logout函数修改为window.top.location.href ,该怎么window.top.location.href ? 这两者之间的主要区别是什么?

谢谢

i have 2 pages, page1.html(mypage), and page2.html(external), page1.html is loading page2.html using iframe. page2.html have basically information of user, it contain menus , forms. There is a logout function with below code

$('#inetLogoutId').click(function(event) { var logoutMsg = "Are you sure you want to log out?"; dialogConfirm(logoutMsg, function() { top.document.location.href = path + "/logout"; }) });

logout not working because of Uncaught DOMException: Blocked a frame with origin "https://example.com" from accessing a cross-origin frame., what if logout function is modified to window.top.location.href. What's the main difference between these 2.

Thank you

最满意答案

当iframe位于不同的域名时,您无法访问iframe的父级。

虽然你可以用另一种方式解决这个问题: http : //madskristensen.net/post/iframe-cross-domain-javascript-calls

You cannot have acces to the parent of the iframe when it is on a different domain name.

Although you can solve this in another way: http://madskristensen.net/post/iframe-cross-domain-javascript-calls

更多推荐

本文发布于:2023-07-28 23:29:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1310165.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Window   iframe   document   top

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!