Charls
Charls

Reputation: 243

Can't change properties of a window object using javascript

I'm trying to create a window and change its properties dynamically.

But when I load a web page (ex : www.google.com) : loads perfectly; and press "Red" button the window moves back and doesn't change its background color.

Here is my code:

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>

Upvotes: 0

Views: 812

Answers (1)

guymid
guymid

Reputation: 1206

For security reasons you cannot manipulate third party site content without permissions from those sites or workarounds. See details about Same Origin Policy and sharing Cross Origin Resources.

If the window content was another page from your own site the code should work.

Upvotes: 3

Related Questions