cross-browser print command?

岁酱吖の 提交于 2019-11-30 04:31:16

问题


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

回答1:


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.




回答2:


window.print() will do the job.




回答3:


That is the general way. It is not an official part of the dom. I would check for its existence first.



来源:https://stackoverflow.com/questions/7458948/cross-browser-print-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!