Set IFrame Style Using JavaScript?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • delraydog@gmail.com

    Set IFrame Style Using JavaScript?

    I'm creating a dynamic iframe element:

    var iframe=document .createElement( "iframe");

    I want attach a style to the element, overflow-x:hidden. However, I can
    not find a way to do this via JavaScript. For example, the following do
    NOT work:

    iframe.style.ov erflow-x="hidden";
    iframe.style="{ overflow-x:hidden;"};

    Any ideas?

    Thanks!
    Cliff.

  • Martin Honnen

    #2
    Re: Set IFrame Style Using JavaScript?



    delraydog@gmail .com wrote:
    [color=blue]
    > I'm creating a dynamic iframe element:
    >
    > var iframe=document .createElement( "iframe");
    >
    > I want attach a style to the element, overflow-x:hidden. However, I can
    > not find a way to do this via JavaScript. For example, the following do
    > NOT work:
    >
    > iframe.style.ov erflow-x="hidden";
    > iframe.style="{ overflow-x:hidden;"};[/color]

    Generally with CSS property-name you use
    element.style.p ropertyName
    so
    iframe.style.ov erflowX = "hidden";
    is the right syntax. Not sure however it makes much sense to set that
    property on an iframe but if it has the right effect for you with static
    CSS then of course setting it dynamically with script should work the same.

    --

    Martin Honnen

    Comment

    • delraydog@gmail.com

      #3
      Re: Set IFrame Style Using JavaScript?

      What I'm really trying to do is to remove the horizontal scrollbar on a
      dynamically created IFrame. The only thing I've found is setting
      scrolling=no but this has the unwanted effect of removing the vertical
      scrollbar also. Setting the overflowX property as you indicated does
      not seem to do anything... so I'm still trying to figure out how to
      prevent that horizontal scrollbar from appearing...

      Thanks for your tip... if you've got another suggestion for the
      horizontal scrollbar problem I'd like to hear it.

      Thanks,
      Cliff.

      Comment

      • Martin Honnen

        #4
        Re: Set IFrame Style Using JavaScript?



        delraydog@gmail .com wrote:
        [color=blue]
        > What I'm really trying to do is to remove the horizontal scrollbar on a
        > dynamically created IFrame. The only thing I've found is setting
        > scrolling=no but this has the unwanted effect of removing the vertical
        > scrollbar also. Setting the overflowX property as you indicated does
        > not seem to do anything... so I'm still trying to figure out how to
        > prevent that horizontal scrollbar from appearing...[/color]

        You need to apply the CSS inside the document of the iframe, there you
        need a rule
        html, body { overflow-x: hidden; }
        I don't think CSS applied to the <iframe> element will help.


        --

        Martin Honnen

        Comment

        • Vic Sowers

          #5
          Re: Set IFrame Style Using JavaScript?


          <delraydog@gmai l.com> wrote in message
          news:1115563870 .246140.249870@ f14g2000cwb.goo glegroups.com.. .[color=blue]
          > I'm creating a dynamic iframe element:
          >
          > var iframe=document .createElement( "iframe");
          >
          > I want attach a style to the element, overflow-x:hidden. However, I can
          > not find a way to do this via JavaScript. For example, the following do
          > NOT work:
          >
          > iframe.style.ov erflow-x="hidden";
          > iframe.style="{ overflow-x:hidden;"};
          >
          > Any ideas?
          >
          > Thanks!
          > Cliff.
          >[/color]

          In scripts it's "overflowX" , not "overflow-x"

          In IE (at least) the iframe must be referenced as an element of the
          document.all collection, so:

          document.all.if rame.style.over flowX = "hidden";

          might work.


          Comment

          • Thomas 'PointedEars' Lahn

            #6
            Re: Set IFrame Style Using JavaScript?

            Vic Sowers wrote:
            [color=blue]
            > In IE (at least) the iframe must be referenced as an element of the
            > document.all collection,[/color]

            No, it need not.
            [color=blue]
            > so:
            >
            > document.all.if rame.style.over flowX = "hidden";
            >
            > might work.[/color]

            Even in IE,

            document.frames['iframe'].style.overflow X = "hidden";

            suffices. No need for IE only code.

            And please read the FAQ on proper quoting.


            PointedEars

            Comment

            Working...