为window.open设置新的favicon

时间:2014-01-20 18:37:27

标签: javascript hyperlink header favicon rel

这将通过REST服务在应用程序外部的新选项卡上显示pdf。如何为此新标签设置favicon?

window.open(App.Config.appPath('doc/images/pdf'),'Image');

1 个答案:

答案 0 :(得分:2)

加载新页面时添加图标:

var newWindow = window.open(App.Config.appPath('doc/images/pdf'), '_blank');
var script = "<sc" + "ript>" 
+ "(function() {" + "   var link = document.createElement('link');" + "   link.type = 'image/x-icon';" + "   link.rel = 'shortcut icon';" + "   link.href = 'link to favicon.ico';" + "   document.getElementsByTagName('head')[0].appendChild(link);" + "}());" + "</sc" + "ript>";

newWindow.document.writeln(
    '<html><head><title>My title</title>' + script + '</head>' + '<body onLoad="self.focus()">' + '</body></html>'
);