简体   繁体   中英

resizeBy not working and don't know why

Why doesn't my resize button resize the window that my "create window" -button creates? I have searched and none of the answers I've found work. I'm all out of ideas now. Please help!

<div id="windowbuttons">
<button onclick="openWin()">Create window</button>
<button onclick="resizeWin()">Resize window</button>

<script>
var myWindow;

function openWin()
{
myWindow = window.open("http://www.google.com","", "width=100,height=100");
}

function resizeWin()
{
myWindow.resizeBy(250,250);
myWindow.focus();
}
</script>
</div>

And it does work correctly when I delete the url from window.open, so that it looks like

function openWin()
{
myWindow = window.open("","", "width=100,height=100");
}

What is going on?

 var myWindow; function openWin() { myWindow = window.open("http://localhost","", "width=100,height=100"); } function resizeWin() { myWindow.resizeBy(250,250); myWindow.focus(); } 
 <div id="windowbuttons"> <button onclick="openWin()">Create window</button> <button onclick="resizeWin()">Resize window</button> </div> 

You are opening http://google.com in a new window and then you are trying to resize http://google.com from your script, which is restricted. In order to work this, your child window must reside on the same host and port as of your parent window

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM