【问题标题】:Window.open problems in html [duplicate]html中的Window.open问题[重复]
【发布时间】:2019-08-16 09:57:18
【问题描述】:

我正在尝试使用按钮打开一个新窗口。窗口需要具有特定的高度和宽度。每当我单击“打开”按钮时,它只会打开一个全新的选项卡。

var aWindow;

function openWindow() {
  aWindow = window.open("", "", "width=400, height = 200");
}

function closeWindow() {
  if (aWindow) {
    aWindow.close();
  }
}
<html>

<body>
  <button onclick="openWindow();">Open</button>
  <button onclick="closeWindow();">Close</button>
</body>

</html>

【问题讨论】:

标签: javascript html window.open


【解决方案1】:
window.open(this.href,'targetWindow','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=300px,height=300px');

试试这个代码测试

【讨论】:

  • 同样的问题发生
  • 你在 Firefox 中测试吗?
  • 我正在虚拟机上对其进行测试,然后在 chrome 中运行它。我以前从未遇到过虚拟机问题
【解决方案2】:

尝试使用此代码

 window.open('https://www.google.co.in/','_blank','toolbar=no, location=no, status=no, menubar=no, scrollbars=yes,resizable=yes, width=10px, height=20px')

DEMO LINK

【讨论】:

  • 当我将它输入代码然后运行它时,它不会弹出一个窗口
  • @JohnKosmalski : 它的工作请查看演示链接
  • 可能是我使用 chrome 的问题吗?
  • @JohnKosmalski : 我在 chrome 上测试了它
  • 当我点击链接时,它会打开一个新标签页。
【解决方案3】:
<input type="button" value="Open a Popup Window" onclick="popupFunction('https://stackoverflow.com')">

<script>
    // Popup window function
    function popupFunction(url) {
popupWindow = window.open(url,'popUpWindow','height=500,width=500,left=100,top=100,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no, status=yes');
    }
</script>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-16
    • 2014-12-30
    • 1970-01-01
    • 2019-12-13
    • 2011-03-28
    • 2011-04-07
    • 1970-01-01
    • 2021-05-21
    相关资源
    最近更新 更多