문제

I have one page in HTML , there are two buttons , save and print.

When user click on the Print it should print the page and When user click on the Save page it should Open Save as... Box for that page.

javascipt/jquery solution preferred.

Thanks.

도움이 되었습니까?

해결책

For printing you can use window.print().

There is no standard way to trigger the Save dialog. In IE you can use document.execCommand('SaveAs').

EDIT: Technically window.print isn't part of any standard (Source: MDC) but it's widely available.

다른 팁

try: (this is just for "save as") ripped and edited from here

<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>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top