Anonymous Anonymous - 3 months ago
3293 0

Example how to print an external url without visiting / opening the external page / website.

Javascript

Print an external url without opening the external url

<script type="text/javascript">
            function closePrint () {
                document.body.removeChild(this.__container__);
            }

            function setPrint () {
                this.contentWindow.__container__ = this;
                this.contentWindow.onbeforeunload = closePrint;
                this.contentWindow.onafterprint = closePrint;
                this.contentWindow.focus(); // Required for IE
                this.contentWindow.print();
            }

            function printPage (sURL) {
                var oHiddFrame = document.createElement("iframe");
                oHiddFrame.onload = setPrint;
                oHiddFrame.style.visibility = "hidden";
                oHiddFrame.style.position = "fixed";
                oHiddFrame.style.right = "0";
                oHiddFrame.style.bottom = "0";
                oHiddFrame.src = sURL;
                document.body.appendChild(oHiddFrame);
            }
        </script>

        <button onClick="printPage('http://externalurl.org');">PRINT</button>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download