admin管理员组文章数量:1355713
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 "" 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
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." 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
Share Improve this question asked May 15, 2017 at 8:38 Nisar AfridiNisar Afridi 1571 gold badge5 silver badges21 bronze badges 2- 1 For the second part of your question use this link: stackoverflow./questions/3332756/… – Jose Marques Commented May 15, 2017 at 8:42
- 1 You can not use java script to perform this function. Use the link to lern more: stackoverflow./questions/25098021/… – Jose Marques Commented May 15, 2017 at 8:49
4 Answers
Reset to default 1You 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/post/iframe-cross-domain-javascript-calls
we have to use window.top.location.href = path + "/logout";
This is due to same-origin-policy. You have keep your all files on the same website or host. Same-origin policy prevents access to cross origin.
You can use document.referrer
to referrer to the parent window.
https://developer.mozilla/en-US/docs/Web/API/Document/referrer#value
本文标签: javascriptWindowtop and topdocument in iframeStack Overflow
版权声明:本文标题:javascript - Window.top and top.document in iframe - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744025454a2577963.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论