Javascript窗口没有显示正确的尺寸而没有调整大小?

时间:2015-11-06 16:38:53

标签: javascript html browser

var customWindow = window.open("http://www.wrox.com/", "height=200,width=100,top=900,left=970,resizable=yes");

无论我在代码中更改了多少窗口尺寸,当我运行代码时,窗口都会以相同的尺寸打开。此外,窗口在具有不同尺寸的不同位置打开,使用chrome与eclipse中的默认系统Web浏览器。

  1. 为什么,改变尺寸不会改变窗口尺寸?
  2. 为什么,eclipse浏览器与chrome的窗口位置和尺寸会有所不同?
  3. 虽然调整大小标志设置为true,但是'调整大小'事件无效。为什么会这样?
  4. <!DOCTYPE html>
    
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    
    <script type = "text/javascript">
        var customWindow = window.open("http://www.wrox.com/", "height=200,width=100,top=900,left=970,resizable=yes");
    //  customWindow.document.write("my window"); 
    
        function customMoveBy() {
            //move the window right by 250 pixels and down by 250 pixels 
            customWindow.moveBy(250, 250);
            customWindow.focus();
        }
    
        function customResizeTo() {
            //resize the window to have a width of 150 and a height of 300 
            customWindow.resizeTo(150, 300);
            customWindow.focus();
        }
    
        function customResizeBy() {
            //resize the window to be 150 pixels wider, but leave the height alone 
            customWindow.resizeBy(150, 0);
            customWindow.focus();
        }
    
        function customMoveTo() {
            //move back to the upper-left corner of the screen (0,0) 
            customWindow.moveTo(0, 0);
            customWindow.focus();
        }
    
        function customClose() {
            customWindow.close();
        }
    
    </script>
    
    
    </head>
    <body>
    <input type = "submit" value = "moveBy" onclick = "customMoveBy()"> </input>
    <input type = "submit" value = "resizeTo" onclick = "customResizeTo()"> </input>
    <input type = "submit" value = "resizeBy" onclick = "customResizeBy()"> </input> 
    <input type = "submit" value = "moveTo" onclick = "customMoveTo()"> </input>
    <input type = "submit" value = "customClose" onclick = "customClose()"> </input>
    </body>
    </html>
    

3 个答案:

答案 0 :(得分:3)

你没有正确地调用open函数,它是

window.open(URL,name,features,replace)

,您将功能字符串放在&#34; name&#34;参数的位置

答案 1 :(得分:1)

&#13;
&#13;
    var customWindow;
     //  customWindow.document.write("my window"); 

    function customMoveBy() {
      //move the window right by 250 pixels and down by 250 pixels 
      customWindow.moveBy(250, 250);
      customWindow.focus();
    }

    function customResizeTo() {
      //resize the window to have a width of 150 and a height of 300 
      customWindow.resizeTo(150, 300);
      customWindow.focus();
    }

    function customResizeBy() {
      //resize the window to be 150 pixels wider, but leave the height alone 
      customWindow.resizeBy(150, 0);
      customWindow.focus();
    }

    function customMoveTo() {
      //move back to the upper-left corner of the screen (0,0) 
      customWindow.moveTo(0, 0);
      customWindow.focus();
    }

    function customClose() {
      customWindow.close();
    }

    function open() {
      customWindow = window.open("", "myWindow", "width=200, height=100");
    }
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="submit" value="moveBy" onclick="customMoveBy()"></input>
<input type="submit" value="resizeTo" onclick="customResizeTo()"></input>
<input type="submit" value="resizeBy" onclick="customResizeBy()"></input>
<input type="submit" value="moveTo" onclick="customMoveTo()"></input>
<input type="submit" value="customClose" onclick="customClose()"></input>
<input type="submit" value="Open" onclick="Open()"></input>
&#13;
&#13;
&#13;

答案 2 :(得分:1)

第二个参数是名称。规格是第三个参数。这应该是

  

var customWindow = window.open(&#34; http://www.wrox.com/&#34;,&#34; name&#34;,&#34; height = 200,width = 100,top = 900,left = 970,可调整大小= YES&#34);

但是html的主要问题,并非一切都在无处不在