javascript - Window.top and top.document in iframe - Stack Overflow

i have 2 pages, page1.html(mypage), and page2.html(external), page1.html is loading page2.html using if

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
Add a ment  | 

4 Answers 4

Reset to default 1

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/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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744025454a4545611.html

相关推荐

  • javascript - Window.top and top.document in iframe - Stack Overflow

    i have 2 pages, page1.html(mypage), and page2.html(external), page1.html is loading page2.html using if

    9天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信