Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/125.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Jquery处理ContentWindow错误的跨域错误_Jquery_Cross Domain - Fatal编程技术网

使用Jquery处理ContentWindow错误的跨域错误

使用Jquery处理ContentWindow错误的跨域错误,jquery,cross-domain,Jquery,Cross Domain,我有一个iframe,在父窗口中有一个后退按钮。我希望“后退”按钮与“浏览器历史记录”按钮完全相同。问题在于跨域。如果我单击打开另一个域页面,那么我的代码将抛出错误 这是我的代码 错误 错误:访问属性“历史记录”的权限被拒绝 document.getElementById(“显示文件”).contentWindow.history.go(-1) 我不寻找一个确切的解决方案,因为我知道跨域问题(另一方面,如果有任何溶胶。请让我知道)。我只想使用jQuery正确处理这些错误,以便获得更好的最终用户体

我有一个iframe,在父窗口中有一个后退按钮。我希望“后退”按钮与“浏览器历史记录”按钮完全相同。问题在于跨域。如果我单击打开另一个域页面,那么我的代码将抛出错误

这是我的代码

错误

错误:访问属性“历史记录”的权限被拒绝 document.getElementById(“显示文件”).contentWindow.history.go(-1)

我不寻找一个确切的解决方案,因为我知道跨域问题(另一方面,如果有任何溶胶。请让我知道)。我只想使用jQuery正确处理这些错误,以便获得更好的最终用户体验。


善意的建议

通过在代码周围添加一个try-catch来解决

try {
 document.getElementById("show-file").contentWindow.history.go(-1); 
 window.iFrameChanges -= 1;
}
catch(err) {
window.iFrameChanges = -1;

    ## code to show message to user (if required) ##            
}
try {
 document.getElementById("show-file").contentWindow.history.go(-1); 
 window.iFrameChanges -= 1;
}
catch(err) {
window.iFrameChanges = -1;

    ## code to show message to user (if required) ##            
}