这有点复杂,请耐心等待.网站A有一个包含网站B的iframe,网站B有一个包含网站C的iframe.
网站C上有一个按钮,点击后,我想刷新网站B的网址.下面是从网站C刷新网站B的javascript,它位于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 to the desired url location: " + dft_url);}
}
}
Run Code Online (Sandbox Code Playgroud)
但是当行"window.parent.location.href = dft_url;"时 得到执行,我收到以下错误:
Unsafe JavaScript attempt to initiate navigation for frame with URL
'https://websiteB.com' from frame with URL
'https://websiteC.com'. The …Run Code Online (Sandbox Code Playgroud)