faqts : Computers : Programming : Languages : JavaScript : Document

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

24 of 26 people (92%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

Can I script the left margin of a page?
Can I script the left margin of a page?
Can I script the left margin of a page?

Mar 22nd, 2000 07:23
Martin Honnen,


IE4+ only supports the 
 <BODY LEFTMARGIN="20">
HTML attribute which you can script as
  document.body.leftMargin 
Note that it is a string so if you want to add values use parseInt on 
it:

<HTML>
<HEAD>
</HEAD>
<BODY LEFTMARGIN="20" 
      ONCLICK="document.body.leftMargin = 
                 parseInt(document.body.leftMargin) + 5;"
>
<A HREF="http://www.kibo.com">
Visit GOD
</A>
<BR>
<A HREF="http://JavaScript.FAQTs.com">
JavaScript.FAQTs.com
</A>
</BODY>
</HTML>

Anyway the better way to specify margins is css so use
  <BODY STYLE="margin-left: 20px;">
and script
  document.body.style.marginLeft
and you have style settings and code running in IE4+ and NN6 (or NN6 as 
they seem to intend to call it). Example

<HTML>
<HEAD>
<SCRIPT>
</SCRIPT>
</HEAD>
<BODY STYLE="margin-left: 20px;" 
      ONCLICK="var ml = parseInt(document.body.style.marginLeft);
                 document.body.style.marginLeft = (ml + 5) + 'px';"
>
<A HREF="http://www.kibo.com">
Visit GOD
</A>
<BR>
<A HREF="http://JavaScript.FAQTs.com">
JavaScript.FAQTs.com
</A>
</BODY>
</HTML>

NN4 will honour the css left-margin setting for BODY but doesn't allow 
to change it with scripting (unless you reload the complete page and 
rewrite it).