简体   繁体   中英

After I open a window using window.open, can I resize its dimensions at will?

I realize that most browsers block window resizing but was wondering that since I am the parents of this newly opened window, would I have any priveleges over sizing it not just on the Open but after?

I am not trying to annoy users either :) I specifically need to keep 2 windows in sync (Same size).

Yes, you have control, here is the example from this site:

http://www.javascriptkit.com/javatutors/advwin4.shtml

<script type="text/javascript">
var mylocation="../index.shtml"
var winheight=100
var winsize=100
var x=5

function go(){
  win2=window.open("","","scrollbars")

  if (!document.layers&&!document.all){
    win2.location=mylocation
    return
  }

  win2.resizeTo(100,100)
  win2.moveTo(0,0)
  go2()
}

function go2(){
  if (winheight>=screen.availHeight-3)
  x=0
  win2.resizeBy(5,x)
  winheight+=5
  winsize+=5

  if (winsize>=screen.width-5){
    win2.location=mylocation
    winheight=100
    winsize=100
    x=5
    return
  }

  setTimeout("go2()",50)
}

</script>
<a href="javascript:go()" onMouseover="window.status='open window';return true" onMouseout="window.status=''" >Open window</a>

Yes, you could set the feature variable for the window to be resizable. Keep the 2nd parameter, window name, the same. The opened window will get updated.

Take a look here: Link pretty much all the functionality of window.open is described in that article.

So, something like:

window.open ("www.example.com", "mywindow","width:100,height:100");

//something happens here, so you need to resize the window

window.open ("www.example.com", "mywindow","width:250,height:250");

The second parameter of the window.open method allows you to specify a window name, so I presume you would be able to resize the window using JavaScript, referencing the window by name, after the window has been opened, yes.

I'm not too hot on JavaScript, so unable to provide a written example off-hand, but in theory it should be possible.

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