带有window.open的跨域对象上的SecurityError [英] SecurityError on cross-origin object with window.open

查看:54
本文介绍了带有window.open的跨域对象上的SecurityError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下面的javascript代码,当您单击图片(img标签)时执行,它还使用了名为photoOrder的数组.

I have the javascript code below that executes when you click on a picture (img tag), it uses also the array called photoOrder.

var photoOrder = [1,2,3,4,5];
//Open center figure in separate window
function bigPicture() {
var propertyWidth = 900;
   var propertyHeight = 550;
   var winLeft = ((screen.width - propertyWidth) / 2);
   var winTop = ((screen.height = propertyHeight) / 5);
   var winOptions = "width=900,height=550";
   winOptions += ",left=" + winLeft;
   winOptions += ",top=" + winTop;
   var bigPicWindow = window.open("./biggerPicture.html", "BiggerPicture", winOptions);
   bigPicWindow.focus();
}

在接收窗口上,我具有以下代码来访问photoOrder数组:

On the receiving window, I have the following code to access the photoOrder array:

var photoOrderArray = window.opener.photoOrder;

主要思想是查看显示的IMG的biiger版本.但是,当我单击它时,window.open调用的第二个窗口出现以下错误:

The main idea is to view a biiger version of the IMG that is displayed. But when I click on it, the second windows called by window.open has got the following error:

SecurityError:拒绝访问跨域对象上的属性"photoOrder"的权限

SecurityError: Permission denied to access property "photoOrder" on cross-origin object

该如何解决?我尝试了window.postMessage,但这只是打开了一个新的带错误的蠕虫罐.我通过双击index.html文件在本地PC上运行它.这是我正在忙的学习项目,而不是实时网站.

how do I fix this? I tried window.postMessage but that just opens a new cans of worms with errors. I am running it on my local pc by double clicking on the index.html file. Its a study project I am busy with, not a live website.

推荐答案

似乎唯一的解决方法是设置Web服务器,即使仅使用Xamp之类的简单设置即可避免错误,因此它可以实时运行以Xamp计算机IP为域的网站.

Seems the only way around it is to setup a web server, even just with a simple setup like Xamp to get away from the error so it runs as a live website having the Xamp computer IP as the domain.

这篇关于带有window.open的跨域对象上的SecurityError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆