ファビコンが独自のWebサイトからのものである場合、あなたは(id
属性を持つ)ファビコンのリンクが含まれているprint.html
テンプレートページ作成できます。ボタンがある場合は
<!DOCTYPE html>
<html>
<head>
<link id="favicon" rel="shortcut icon" type="image/x-icon" href="favicon.ico" />
</head>
<body>
</body>
</html>
をクリックすると、そのページが開き、追加のコンテンツがheadセクションとbodyセクションに挿入されます。私のテストによると、DOMにfaviconリンクが存在することは、ページの内容をいつ変更できるかを判断する良い指標となります。 ChromeとFirefoxの場合、変更は$(wnd).load()
で行うことができます。 Internet Explorer 11の場合は、$(wnd.document).ready()
で作成できます。
$("#btnOpenWindow").click(function() {
var done = false;
// Open the window with the empty page
var wnd = window.open("print.html");
// For Chrome and Firefox
$(wnd).load(function() {
injectContent();
});
// For Internet Explorer
$(wnd.document).ready(function() {
injectContent();
});
function injectContent() {
// If the favicon link is loaded in the DOM, the content can be modified
if (!done && $("#favicon", wnd.document).length > 0) {
done = true;
$("head", wnd.document).append("<title>The window title</title>");
$("body", wnd.document).append("<h1>Main title</h1>");
...
}
}
});
あなたは本当にあなたが以下のように変更して、上記と同様の方法を使用することができ、新しいウィンドウのファビコンを変更する必要がある場合:
<link id="favicon" rel="shortcut icon" type="image/x-icon" />
function injectContent() {
if (!done) {
var $favicon = $("#favicon", wnd.document);
if ($favicon.length > 0) {
done = true;
var faviconUrl = window.location.protocol + "//" + window.location.host + "/favicon.ico";
$favicon.attr("href", faviconUrl);
$("head", wnd.document).append("<title>The window title</title>");
$("body", wnd.document).append("<h1>Main title</h1>");
...
}
}
}
私はこれの有用性について不思議ですが、それは興味深い問題です。 –
これは請求書を印刷するためのものです。ユーザーがすべてのUIなしで彼の請求書の印刷版を入手できるように、HTMLを受け取る新しいウィンドウがあります。 – frenchie