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