简体   繁体   中英

Unable to implement print preview in javascript?

I am trying to implement the print preview on a page that opens as pdf format.However, when the page opens , the print function is not executed and nothing happens. What could I be doing wrong? I am using Python with Django and I want to implement the print function using javascript.

Try function assignment without executing the function (without parathesis).

window.onload = funcloadprint;

And maybe put the assigment after the declaration, not before.


A little suggestion

It is good practice to wrap your javascript code in a closure to avoid global namespace polution. Its not necessary for this small case, but it would be good for your future projects to read up about it.

(function() {
    function funcloadprint() {
        ...
    };
    window.onload = funcloadprint;
})();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM