Monday, September 12, 2011

Print this Page and Open New window in Drupal

 Use this printPage() and openWin() Function in your main js file and call this where ever you want to print a page and Opens in a new window popup respectively.

function printPage() {
    var agt = navigator.userAgent.toLowerCase();
    var is_win = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
    var is_mac    = (agt.indexOf("mac")!=-1);
    var macos  = (is_mac && ((agt.indexOf("mac os") != -1) || (agt.indexOf("macos") != -1) || this.ie));
    var macosx = (macos && ((agt.indexOf("os x") != -1) || (agt.indexOf("osx") != -1)));

    if(macosx || is_win ){
        window.print();
    } else {
        alert("To print this page, press 'command+P'.");
    }
}

function openWin(theURL, windowName, features) {
    newWin = window.open(theURL, windowName, features);
    newWin.focus();
}

 Ex:
onclick="javascript:window.open('<?php print base_path();?>privacy_page(your URI)','popup(Window name)','width=625,height=600,scrollbars=1'(features));

Then,cal this function in your module file:

** printPage() function is used to print a page

**openWin() is used to open a page in a new window,ther you can use the print option also




No comments:

Post a Comment