...sorry - I should have explained what it is that I'm trying to do with this code: I am trying to set the print margins programmatically. I do have a CSS in my project. Will that help?
Sorry, still not getting it. Are you trying to print on the client programmatically, or just set print margins on the page programmatically (ie, based on some dynamic content) leaving the actual printing to the user?
There's a (JavaScript) print button on the screen. When the user clicks that, a [tt]Window.print()[/tt] is executed and a print dialogue box pops up. I do not want to make the users change their margins manually each time. I would like it to change their margins at that point - right before they print that screen.
Any stylesheet rules that are declared in a specific media section are only applied to that media. Hence, if you set margins in a print media, it will only affect the page when printing (and something like print-preview). So you don't have to programmatically change them at time of printing, just set them when you send the page to the client under a media section for print.
Note that these aren't printer page margins, they're just like margins for how the content is displayed in a browser, but instead of a window, it's paper. If you're trying to increase margins, that will probably work fine, but decreasing likely won't. There may be client-side scripting ways to change formal page margins, but I don't know how. I think that's beyond what CSS can do (though I could be wrong, anyone to support or refute?).
Printer settings are firmly in the domain of "user controlled". The only thing that JavaScript's print() method does, is relay the request to the browser, which relays the request to the OS, which opens a Print Dialog.
This is as it should be. I don't want a web page altering settings to my printer, changing the orientation, silently printing, etc.
The CSS "print" settings are not widely supported. And as pointed out, all they do is affect the placement/appearance of the CONTENT within the context of the current media. The user sets that context.
Think in terms of the default "media", the browser window. I can position my window on my screen wherever I like it. The margins and positions of the page elements relate to the window, not the screen.
I know, I know - you can write JavaScript to change the position of the window on the screen and resize the browser window and so on. ALL of which is EVIL .
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.