javascript 更改 window.open 的标题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4139148/
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
Change the title of window.open
提问by Gas
I have a window.open function call on click, which opens an .swf albumplayer.
单击时我有一个 window.open 函数调用,它会打开一个 .swf 专辑播放器。
var win = null;
function NewWindow(wizpage, wizname, w, h, scroll){
LeftPosition = (screen.width) ? (screen.width-w)-8 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings = 'height=' + h + ',width=' + w + ',top= 100,' + TopPosition + ',left=' + LeftPosition + ',scrollbars=' + scroll + ',resizable';
win = window.open(wizpage, wizname, settings);
}
I would want to change the title of the opened window, that it has some meaningful title (a constant 'Album Player' or something would be fine), so that doesn't use the default filename/application-shockwave... text.
我想更改打开的窗口的标题,它有一些有意义的标题(一个常量“专辑播放器”或其他东西就可以了),这样就不会使用默认的文件名/应用程序冲击波...文本。
Thanks for the help.
谢谢您的帮助。
回答by Roman
Then put it to onload event:
然后把它放到onload事件中:
win.onload = function() { this.document.title = "your new title"; }
回答by John Hartsock
Try this
试试这个
var win = null;
function NewWindow(wizpage, wizname, w, h, scroll){
LeftPosition = (screen.width) ? (screen.width-w)-8 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings = 'height=' + h + ',width=' + w + ',top= 100,' + TopPosition + ',left=' + LeftPosition + ',scrollbars=' + scroll + ',resizable';
win = window.open(wizpage, wizname, settings);
win.document.title = "your new title";
}
回答by JJ Jasper Loubser
function fnDurationPrint(displayText, dateText) {
var WindowObject = window.open('', "DurationText", "width=430,height=250,top=200,left=250,toolbars=no,scrollbars=yes,status=no,resizable=no");
WindowObject.document.writeln("<li>" + displayText + "</li>");
WindowObject.document.title = "Duration Text of " + dateText;
}
//WindowObject.document.title = must always be last after all code in javascript function
//WindowObject.document.title = 必须始终在javascript函数中的所有代码之后

