简体   繁体   中英

Javascript print function uses the printer on browser instead

For some reason using

    var sample = "test";
    print(sample);

the print function doesn't print the string on the web browser , however it literally uses the print function on my chrome browser . any idea why ? Im actually learning javascript from http://eloquentjavascript.net/ and it uses the print function too.

The window.print() method opens the print dialog to print the current document, Not part of any standard. ( from MDN )

If you want to print something in your page, use document.write() function. The text you write is parsed into the document's structure model

read more at MDN - document.write()

if you want to print something for simple debugging purpose, use console.log() , which prints the output in browsers console. read more at MDN - console.log()

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