Solved

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

Posted on 2004-10-03
8
660 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
 

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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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 …
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now