jquery - Unsafe JavaScript attempt to initiate navigation for frame with URL -
this bit complicated, please bear me. website has iframe contains website b , website b has iframe contain website c.
there button on website c, when clicked, want refresh url of website b. below javascript called refresh of website b website c, in iframe
function url_update(id){ var host = 'https://websiteb.com '; var myhost = host.split('/'); if (id != "" && myhost != ""){ try { if (id.substring(0,1) != '/'){ id = '/' + id; } var dft_url = myhost[0] + '//' + myhost[2] + id; window.parent.location.href = dft_url; } catch(e){alert("cannot go desired url location: " + dft_url);} } } but when line "window.parent.location.href = dft_url;" gets executed, received following error:
unsafe javascript attempt initiate navigation frame url 'https://websiteb.com' frame url 'https://websitec.com'. frame attempting navigation neither same-origin target, nor target's parent or opener. i don't understand why happening , how fix it. appreciated.
i did research, claimed origin problem, if take out website a, meaning have website b iframe contains website c, above code works. though have different domains
you can find explanation of behavior in comment of chromium source code. see here:
basically top-level windows have less restrictions regarding navigation other windows. see restrictions non top windows:
a document can navigate decendant frames, or, more generally, document can navigate frame if document in same origin of frame's ancestors (in frame hierarchy).
where top window:
specifically, document can navigate top-level frame if frame opened document or if document same-origin of top-level frame's opener's ancestors (in frame hierarchy).
reason is:
top-level frames easier navigate other frames because display urls in address bar (in browsers).
so basically, non top window, absolutely needs same origin allow navigation, top windows, frame opened window can navigate if it's not same-origin. seems problem you're facing, when b top, same origin doesn't apply, when it's not top, applies.
according this, i'm not sure there's straightforward, or @ all, solution.
Comments
Post a Comment