跨浏览器打印命令?
我想知道是否有任何跨浏览器打印代码,也就是说,如果我需要其他代码,那么就很简单:
//print page
$('.print').click(function() {
window.print();
return false;
});
我确实找到了书签,这就是为什么我也更关心打印,但在谷歌上找不到任何有用的东西。
以下代码用于跨浏览器书签
//bookmark page
$("a.bookmark").click(function(e)
{
e.preventDefault(); // this will prevent the anchor tag from going the user off to the link
var bookmarkUrl = this.href;
var bookmarkTitle = this.title;
if (window.sidebar) { // For Mozilla Firefox Bookmark
window.sidebar.addPanel(bookmarkTitle, bookmarkUrl,"");
} else if( window.external || document.all) { // For IE Favorite
window.external.AddFavorite( bookmarkUrl, bookmarkTitle);
} else if(window.opera) { // For Opera Browsers
$("a.jQueryBookmark").attr("href",bookmarkUrl);
$("a.jQueryBookmark").attr("title",bookmarkTitle);
$("a.jQueryBookmark").attr("rel","sidebar");
} else { // for other browsers which does not support
alert('Your browser does not support this bookmark action');
return false;
}
});
i want to know if there is any cross-browser print code, that is if i need other then just simple:
//print page
$('.print').click(function() {
window.print();
return false;
});
i did found for bookmark and thats why i was more concern about print too, but couldn't find anything useful on google.
following code is for bookmark cross-browser
//bookmark page
$("a.bookmark").click(function(e)
{
e.preventDefault(); // this will prevent the anchor tag from going the user off to the link
var bookmarkUrl = this.href;
var bookmarkTitle = this.title;
if (window.sidebar) { // For Mozilla Firefox Bookmark
window.sidebar.addPanel(bookmarkTitle, bookmarkUrl,"");
} else if( window.external || document.all) { // For IE Favorite
window.external.AddFavorite( bookmarkUrl, bookmarkTitle);
} else if(window.opera) { // For Opera Browsers
$("a.jQueryBookmark").attr("href",bookmarkUrl);
$("a.jQueryBookmark").attr("title",bookmarkTitle);
$("a.jQueryBookmark").attr("rel","sidebar");
} else { // for other browsers which does not support
alert('Your browser does not support this bookmark action');
return false;
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
window.print() 是事实上的标准。 (从 IE4/Netscape 4 开始就支持它)。
在进行此操作时,请务必查看如何自定义使用 打印页面时的外观打印特定的 CSS 样式表。
window.print() is a de-facto standard. (it's been supported since the days of IE4/Netscape 4).
While you're at it, be sure to check out how you can customize how your page looks when it's printed using print-specific CSS stylesheets.
window.print()
将完成这项工作。window.print()
will do the job.这是一般的方式。它不是 dom 的官方部分。我会首先检查它是否存在。
That is the general way. It is not an official part of the dom. I would check for its existence first.
首先,您需要将 html 设置为具有与此类似的内容安全策略:
示例:
这里重要的部分是:frame-src blob: data: (blob 部分)
然后,您可以使用“本地”非跨域进行打印通过将 iframe 设置为加载 blob 而不是“外部 URL”的方式
使用以下命令:
First you need to set your html to have Content Security Policy similar to this:
Example:
The important part here is: frame-src blob: data: (the blob part)
Then, you can print using a "local" non cross-domain way by setting the iframe to a load a blob instead of an "outside URL"
Using this: