fre*_*hie 7 javascript favicon
我正在打开一个新窗口,我正在为身体和头部注入HTML.问题出在头部:HTML包括标题和图标,但图标不显示.这是代码和jsFiddle:https://jsfiddle.net/ufnjspgc/
function Start() {
$('#TheButton').click(function() {
var TheHeadHTML = '<link href="' + window.location.protocol + '//' + window.location.host + '/favicon.ico" rel="icon" type="image/x-icon">';
TheHeadHTML = TheHeadHTML + '<title>Title Works</title>';
var TheNewWindow = window.open();
$(TheNewWindow.document.head).html(TheHeadHTML);
});
}
$(Start);
Run Code Online (Sandbox Code Playgroud)
如何让favicon出现在新窗口中?
您可以使用数据URI打开一个新窗口.这是代码:
<input type="button" value="test" id="TheButton" />
function Start() {
$('#TheButton').click(function() {
var TheNewWindow = window.open("data:text/html;charset=utf8,<html><head><link href='" + window.location.protocol + "//" + window.location.host + "/favicon.ico' rel='icon' type='image/x-icon'><title>Title Works</title></head><body></body></html>");
});
}
$(Start);
Run Code Online (Sandbox Code Playgroud)
而小提琴.
基本上,数据URI允许您在URL本身中指定内容,使其不需要转到服务器,或者在您的情况下,转到"about:blank"资源浏览器(必须).由于跨域和其他问题,"about:blank"在编写脚本时会导致很多问题.
正如@ConnorsFan所指出的,这种技术在IE中不起作用.正如Diego Mijelshon 在这个问题中所指出的,IE不允许导航到数据URI,因此它不能用作新窗口的URL.似乎在最新版本的Chrome和Firefox中运行良好.我担心我没有可以测试的Safari副本.
| 归档时间: |
|
| 查看次数: |
3265 次 |
| 最近记录: |