Javascript 打开没有工具栏的窗口

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12711997/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 11:04:54  来源:igfitidea点击:

Open window without toolbars

javascripthtml

提问by Joly

I am trying to open new window without toolbars using the code below but it opens new window with the toolbars (at least in IE). Any idea what am I doing wrong?

我正在尝试使用下面的代码打开没有工具栏的新窗口,但它会打开带有工具栏的新窗口(至少在 IE 中)。知道我做错了什么吗?

<a href="http://www.google.com" onclick="popupWindow(this.href)" target="_blank"><img src="/myImage"/><a>

function popupWindow(url)
{
    window.open(url,"MyWindow","config='toolbar=no, menubar=no,scrollbars=no,resizable=no,location=no,directories=no,status=no'");
}

回答by JYelton

A quick Google search found the syntax for this at DevShed:

一个快速的谷歌搜索在DevShed找到了这个语法:

<script language="javascript">
function myPopup(url, windowname, w, h, x, y)
{
    window.open(url, windowname, "resizable=no, toolbar=no, scrollbars=no, menubar=no, status=no, directories=no, width=" + w + ", height=" + h + ", left=" + x + ", top=" + y);
}
</script>

Note that it differs from your own in that you have config=as part of the last argument, and it's not needed (as AlienWebguy pointed out).

请注意,它与您自己的不同,因为您将其config=作为最后一个参数的一部分,并且不需要(正如 AlienWebguy 指出的那样)。

回答by KatieK

There were several issues in your code:

您的代码中有几个问题:

  • There should be only 3 ws in wwww.google.com
  • Unnecessary config='. Also remove that final closing '.
  • atus=noshould be status=no
  • 应该只有 3 ws wwww.google.com
  • 不必要的config='。也删除最后的结束'
  • atus=no应该 status=no

Correcting these issues makes the pop-up work:

纠正这些问题使弹出窗口工作:

<a href="http://www.google.com" onclick="popupWindow(this.href)" target="_blank">Click</a>
<script type="text/javascript">
function popupWindow(url)
  {
    window.open(url,"MyWindow","toolbar=no, menubar=no,scrollbars=no,resizable=no,location=no,directories=no,status=no");
  }
</script>

回答by Joly

Thanks to everyone for replying.

感谢大家的回复。

The issues mentioned were typos here, they were correct on my original code.

提到的问题是这里的拼写错误,它们在我的原始代码中是正确的。

For some reason in IE the name of the window has to be an empty string. So, if I rename "MyWindow" to "" it works. Strange but googling shows more people have this problem.

出于某种原因,在 IE 中窗口的名称必须是一个空字符串。因此,如果我将“MyWindow”重命名为“”,它会起作用。奇怪但谷歌搜索显示更多人有这个问题。