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:

https://code.google.com/p/chromium/codesearch#chromium/src/third_party/webkit/source/core/frame/frame.cpp&sq=package:chromium&rcl=1438193817&type=cs&l=202

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

Popular posts from this blog

android - Pass an Serializable object in AIDL -

How to provide Authorization & Authentication using Asp.net, C#? -

How to use Authorization & Authentication in Asp.net, C#? -