Solved

JavaScript to set the Internet Explorer browser's "Page Setup" properties

Posted on 2004-10-03
8
699 Views
Last Modified: 2008-01-09
Hello,

I'm looking for a way in JavaScript to be able to set the browsers "Page Setup" properties. I'm specifically talking about IE 6+.  I would like to be able to set the page orientation and margins.  This is needed for printing purposes and not for displaying the page in the browser.  I have a wide table that  I need to print in landscape and adjust the browsers margins to fit this table on the paper. I will be opening a new window for printing this table.  I would like to set these properties myself and not have the user fiddle with them. Is this possible? Any other suggestions if not?

Thanks for any help,
0
Comment
Question by:nmachin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 36

Expert Comment

by:Zyloch
ID: 12211107
Hi nmachin,

I don't know about margins. Try setting negative margins for you body tag with CSS:

<style type="text/css">

body {margin:-10px -10px;}

</style>

and see if that helps. As to printing landscape, it's not as clear with CSS. See here: http://home.tampabay.rr.com/bmerkey/examples/landscape-test.html

Regards,
Zyloch
0
 

Author Comment

by:nmachin
ID: 12211195
Zyloch,

It looks like I'll be able to make the negative margins work for the margin issue.

When I try a simple test html doc as listed below, it doesn't change it to landscape when I attempt to print it through IE.  The page appears in portraite with the right side of the table cut off.

Thanks,
nmachin


<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>test</title>

<style type="text/css" media="print">
div.page      {
writing-mode: tb-rl;
height: 80%;
margin: 10% 0%;
}
</style>

</head>
<body>
<div class="page">
<table border="1" width="900">
      <tr>
            <td>test</td>
      </tr>
</table>
</div>
</body>
</html>
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 12211204
Yeah, data tables don't seem to work. You can try this (which only works for IE6):

div.page table {
margin-right: 80pt;
filter: progid:DXImageTransform.Microsoft.BasicImage(Rotation=1);
}
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:nmachin
ID: 12211246
Zyloch,

I think we're getting close but get some pretty wild results using multiple tables.

<div class="page">
<table border="1" width="900">
     <tr>
          <td>
                <table border="1">
                     <tr>
                           <td>test</td>
                     </tr>
                  </table>
           </td>
     </tr>
     <tr>
          <td>test</td>
     </tr>
</table>
<table border="1" width="900">
     <tr>
          <td>test</td>
     </tr>
</table>
</div>

thanks,
nmachin
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 12212390
That's odd. What do you get with multiple tables? Sorry I don't have a printer available *looks sheepish*
0
 

Author Comment

by:nmachin
ID: 12212416
When I nest the tables as listed,  the contents of table2 appear upside down .... gets rotated twice.

<table border="1" width="900" id="table1" >
     <tr>
          <td>
                <table border="1" id="table2" >
                     <tr>
                           <td>test</td>
                     </tr>
                  </table>
           </td>
     </tr>
</table>

When I put 2 tables side by side, each table is on a different page.

<table border="1" width="900">
     <tr>
                <td>test</td>
     </tr>
</table>
<table border="1" width="900">
     <tr>
                <td>test</td>
     </tr>
</table>
0
 
LVL 36

Accepted Solution

by:
Zyloch earned 500 total points
ID: 12212531
Hmm... This is a bit troublesome. It seems filter applies to everything, even the tables inside it. One possible way is to use two tables, but the second one has relative positioning? A bit "hackish" but I guess it should work.

I'm not too sure about the two tables side by side yet, so I'll let you know
0
 

Author Comment

by:nmachin
ID: 12215247
It looks like I got it!!  I used 1 table and DIV tags to define the nested tables.  Thanks for your help.
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question