我試圖創建一個窗口並動態更改其屬性。無法使用javascript更改窗口對象的屬性
但是當我加載一個網頁(例如: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>
[鏈接](http://stackoverflow.com/questions/2157180/onclick-open-window-and-specific-size)回到這個。 –
是否有任何錯誤記錄在控制檯中?框架受到[相同來源策略](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Same_origin_policy_for_JavaScript)的限制,這將阻止修改您不擁有的資源。 –
謝謝@Atal,但我需要在加載後更改屬性。 :( – Charls