我正在尝试创建一个窗口并动态更改其属性。
但是当我加载网页(例如:www.google.com)时:加载完美;然后按“红色”按钮,窗口向后移动并且不改变其背景颜色。
这是我的代码:
JavaScript:
var win1 ='';
function create(){
var url1=document.getElementById('myUrl').value;
win1=open(url1,'hello', 'width=500,height=500');
}
function makeItRed(){
win1.document.body.style.backgroundColor="red";
win1.focus();
}
function closeIt(){
win1.close();
}
HTML:
<input type="text" id="myUrl"/>
<button onClick="create()">Click</button>
<button onClick="makeItRed()">Red</button>
<button onClick="closeIt()">close</button>
最佳答案
出于安全原因,您无法在没有 permissions from those sites or workarounds 的情况下操纵第三方网站内容。请参阅details about Same Origin Policy和 sharing Cross Origin Resources 。
如果窗口内容是您自己站点中的另一个页面,则代码应该可以工作。
关于javascript - 无法使用 JavaScript 更改窗口对象的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22140659/