Solved

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

Posted on 2004-10-03
8
679 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
  • 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
check a checkbox of a checkboxes group in bootstrap 2 41
Html input text color the frame line 2 20
javascript - insert into js doc help 2 23
Javascript 2 21
In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…

840 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