javascript - 为 window.open 设置新的图标

标签 javascript hyperlink header favicon rel

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

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

最佳答案

加载新页面时添加图标:

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>'
);

关于javascript - 为 window.open 设置新的图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21241612/

相关文章:

javascript - 导航栏特定的 jQuery 滚动动画

javascript - 使用 Ionic React 添加滚动按钮

javascript - 多 View 布局框架7 混合应用程序

javascript - 无法在另一个函数中调用函数

php - 使用 Javascript 和 PHP 将表单数据提交到两个位置?

jquery - "Disable"单击时暂时出现链接?

codeigniter - SEO 友好 URL 的建议

html css链接到另一个链接

c++ - 使用命名空间标准

php - 通过 Javascript 访问 HTTP GET 请求