0

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>
Mike-O
  • 844
  • 1
  • 11
  • 16
Charls
  • 235
  • 1
  • 4
  • 13
  • [link](http://stackoverflow.com/questions/2157180/onclick-open-window-and-specific-size) reffered to this. – Atal Shrivastava Mar 03 '14 at 07:10
  • Are any errors being logged in the console? Frames are restricted by the [same origin policy](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Same_origin_policy_for_JavaScript), which will prevent modification of resources you don't own. – Jonathan Lonowski Mar 03 '14 at 07:30
  • thanks @Atal but I need to change properties after loading. :( – Charls Mar 03 '14 at 07:43
  • yeah @JonathanLonowski i see "Uncaught SecurityError" in log any idea how to fix this?? – Charls Mar 03 '14 at 07:47

1 Answers1

3

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.

Community
  • 1
  • 1
guymid
  • 1,186
  • 8
  • 11
  • thanx. any idea to do what i'm trying?? Once I saw an extension injects a script into the page and do this. Is there any way to access into a window through an extension?? – Charls Mar 03 '14 at 07:50
  • Due to security reasons many sites like google doesn't allow to load in iframes. . – Charls Mar 03 '14 at 07:55
  • The 'proper' ways to do cross domain changes require permissions or code on the other server to enable you to do that, and most sites realistically will not do that. The alternative is to use a proxy so that the content looks like it is coming from your server. What is your actual aim? – guymid Mar 03 '14 at 07:57
  • creating a inspect element-type page. So i can get a list of elements into my page and select and highlight them. Any links about that proxy thing?? links i found are really complex :( – Charls Mar 03 '14 at 08:11
  • You can use and view the code in this open source example http://whateverorigin.org/ – guymid Mar 03 '14 at 08:22