走り方はブラウザのコマンドを使用jQuery/javascript?
-
23-09-2019 - |
質問
いるページのHTMLには、ボタン、保存-印刷が可能になりました。
ユーザーをクリックし、印刷ではページを印刷する場合は、や ユーザーをクリックし保存ページでダブルクオーテーションは付けて保存...ボックスこのページです。
javascipt/jquery溶液が好ましい。
感謝。
解決
印刷に使用でき window.print()
.
ありませんの標準的な方法をトリガーの保存ダイアログを表示します。IEを使用でき document.execCommand('SaveAs')
.
編集:技術的に window.print
ならではの標準(ソース: MDC がで幅広くご利用いただけます。
他のヒント
う:(これは単なる"名前を付けて保存")を作および編集 こちらの
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script >
$(document).ready(function(){
$('a#save').click(function() {
if (!!window.ActiveXObject) {
document.execCommand("SaveAs");
} else if (!!window.netscape) {
var r=document.createRange();
r.setStartBefore($("head")[0]);
var oscript=r.createContextualFragment('<script id="scriptid" type="application/x-javascript" src="chrome://global/content/contentAreaUtils.js"><\/script>');
$('body').append(oscript);
r=null;
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
saveDocument(document);
} catch (e) {
//no further notice as user explicitly denied the privilege
} finally {
//re-defined
$("#scriptid").remove();
}
}
return false;
})
})
</script>
</head>
<body>
<a href="#" id="save">save the document</a>
</body>
</html>
所属していません StackOverflow