0

I think it is an easy questions but I am new in JavaScript

Why buttons "but3" and "but4" not working when I try moveBy or moveTo a new window?

thanks

HTML code

<input type="button" value="New window" id="but1" onclick="createwin()" />
<input type="button" value="close window" id="but2" onclick="closewin()" />
<input type="button" value="moveby window" id="but3" onclick="movebywin()" />
<input type="button" value="moveto window" id="but4" onclick="movetowin()" />

javascript code

var win1;

function createwin(){
    win1 = window.open('http://www.google.com','google','width=500,height=500');
}

function closewin(){
    win1.close();
}

function movebywin(){
   win1.moveBy(100,100);
}

function movetowin(){
  win1.moveTo(100,100);
}
Tarek Saied
  • 6,482
  • 20
  • 67
  • 111

1 Answers1

5

The error message says

Permission denied to access property 'moveBy'

To access the properties of another window, it needs to be in the same domain.

Your code works if you replace www.google.com with a file in the same directory.

lyle
  • 757
  • 1
  • 7
  • 18