javascript 设置Chrome window.open的页面标题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4994063/
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
Setting the page title of Chrome window.open
提问by Will
I have some JavaScript that is being used to open a new window and display a PDF file. This is working fine apart from the title of the new window being open. I am using the window.open function and I have set the title of the page using the document.write function (see code below). The code works fine for FF and IE but for some reason Google Chrome just displays 'Untitled - Google Chrome'
我有一些用于打开新窗口并显示 PDF 文件的 JavaScript。除了打开新窗口的标题外,这工作正常。我正在使用 window.open 函数,并且我已经使用 document.write 函数设置了页面的标题(见下面的代码)。该代码适用于 FF 和 IE,但出于某种原因,谷歌浏览器只显示“无标题 - 谷歌浏览器”
<body>
<a href="javascript:openNewWindow();">Click Here</a>
<script type="text/javascript">
function openNewWindow()
{
var pdfWindow = window.open('', "window",
'resizable=1,scrollbars=0,width=800,height=600');
pdfWindow.document.write('<html><head><title>Window Title</title></head>');
pdfWindow.document
.write('<body><iframe src="" id="ifrm" name="ifrm" width="100%" height="100%"></iframe>');
pdfWindow.document.write('</body></html>');
pdfWindow.document.close();
}
</script>
</body>
Note: I have also tried adding - pdfWindow.document.title="Title"; - to the JavaScript, with no luck.
注意:我也尝试添加 - pdfWindow.document.title="Title"; - 到 JavaScript,没有运气。
Is there anything specific that is required for Chrome or am I just missing something??
Chrome 有什么具体要求吗,或者我只是遗漏了什么?
采纳答案by Dr.Molle
Works for me when I set the 1st parameter of open() to 'about:blank'
当我将 open() 的第一个参数设置为 'about:blank'
回答by Andrey
You need to specify the url in the first parameter, like "about:blank":
您需要在第一个参数中指定 url,例如“about:blank”:
window.open('about:blank', "window", 'resizable=1,scrollbars=0,width=800,height=600');
回答by mohamed hajaji
It will work on Chrome in incognito mode. So the issue is caused by an extension, probablly adblock. Disabling the extensions will solve this issue.
它将以隐身模式在 Chrome 上运行。所以这个问题是由扩展引起的,可能是广告拦截。禁用扩展将解决此问题。
回答by fengtong li
The pop up dialogue/window was blocked by chrome browser by default. If you change settings, that will do.
默认情况下,Chrome 浏览器会阻止弹出的对话/窗口。如果您更改设置,就可以了。

