Open a new javascript window(.open) along with its CSS styling

后端 未结 6 501
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-27 18:50

I\'m trying to get this function to work on the website of a project I\'m working on. The purpose of this function is to only (physically) print the contents of a child div

6条回答
  •  我在风中等你
    2020-11-27 19:06

    I also had the problem with CSS loading after the page rendering, so solution was to read the css file content and write it to the new document:

        var w = window.open();
        jQuery.get('/styles.css', function (data) {
            w.document.write('');
            w.document.write($('.print-content').html());
            w.document.write('');
            w.print();
            w.close();
        });
    

提交回复
热议问题