Skip to content
Advertisement

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

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 which is coincidentally referred to as selector #content.

Here’s the little bit I’ve got ’till now:

JavaScript

The function is fired when a person clicks on a “print” hyperlink. The new window will load the contents of the #content div which is parsed from another HTML document:

JavaScript

It just won’t load the styling along with it. All the contents will all just be cropped up in the top left corner. I’ve tried linking the CSS through JS or by just putting it in the head of the page as suggested on another page. I could be doing this wrong of course. I haven’t really tried figuring this out with JQuery yet, so if you have any other solutions that might help me with my problem, I’m happy and open to receive some advice about them.

Thanks in advance!

Advertisement

Answer

Build a complete HTML page in the opened window and reference your CSS-file there:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement