3

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

Nisar Afridi
  • 157
  • 1
  • 1
  • 19
  • 1
    For the second part of your question use this link: http://stackoverflow.com/questions/3332756/difference-between-window-location-href-and-top-location-href – Jose Marques May 15 '17 at 08:42
  • 1
    You can not use java script to perform this function. Use the link to lern more: http://stackoverflow.com/questions/25098021/securityerror-blocked-a-frame-with-origin-from-accessing-a-cross-origin-frame – Jose Marques May 15 '17 at 08:49

3 Answers3

2

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

Remco K.
  • 631
  • 4
  • 17
  • thank you, i understand cross origin issue, and this link is very good, i have access to both sites, but domain names are different, and i cannot change those, so i have to use second method from that document. – Nisar Afridi May 15 '17 at 08:52
1

we have to use window.top.location.href = path + "/logout";

Nisar Afridi
  • 157
  • 1
  • 1
  • 19
0

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.