i want print the iframe contents using javascript can u help me

And this is my code i can't get the print of iframe

<head>
<script type="text/javascript">
function ClickHereToPrint(){
    try{ 
        var oIframe = document.getElementById('ifrmPrint');
        var oDoc = (oIframe.contentWindow || oIframe.contentDocument);
        if (oDoc.document) oDoc = oDoc.document;
        oDoc.this.print();    
        oDoc.close();       
    }
    catch(e){
        self.print();
    }
}
</script>
</head>


<body>

<a onclick="ClickHereToPrint();">Print</a>

    <iframe id='ifrmPrint' src='#' style="width:0px; height:0px;"></iframe>
    <div id="divToPrint">
        content
    </div>
</body>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.