Setting applet window size using javascript?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Put 030516 in email subj to get thru

    Setting applet window size using javascript?

    I've always been bothered about having to statically declare the size of
    a Java applet window (container?) in the calling HTML. I've always
    wanted the moral equivalent of width=50% statement (of the window or
    frame). I'm trying to use Javascript to do so.

    I can sort of get an example working in a Mozilla browser:
    [color=blue]
    > <!-- This works on Mozilla only (and maybe netscape) -->
    > <script language="Javas cript">
    > document.write( "<applet code=MyApplet.c lass width="
    > + window.innerWid th/2 + " height=" + window.innerWid th/2 +[/color]
    "></applet> <br>" ); </script>


    So the document.write statement produces a normal looking applet string
    like this:

    <applet code=MyApplet.c lass width=252.5 height=252.5></applet>

    Which gets intepreted by the browser, kicking off the Java applet. But
    as you resize the browser the alignment with other text in the html
    window is funky. Also, in the above example, the window.innerWid th is
    apparently from the Mozilla/Netscape DOM, not MS-IE's.

    Does anybody have any Javascript examples of how to dynamically presize
    an applet to some percentage of the window/frame width? (that's mostly
    portable)

    --
    Ben in DC
    PublicMailbox@b enslade.com (put 030516 anywhere in the subj to get thru)
    "It's the mark of an educated mind to be moved by statistics"
    Oscar Wilde

  • VK

    #2
    Re: Setting applet window size using javascript?

    Inline applet (allocated on the web-page) doesn't support resize()
    method: "once done, it's done".

    You can catch resize events from JavaScript and reload the page with
    applet over and over on each resize. Evidently the current state of
    applet will be lost.

    Put 030516 in email subj to get thru <PublicMailbox@ benslade.com> wrote
    in message news:R8gmb.984$ Ui3.950@nwrddc0 2.gnilink.net.. .[color=blue]
    > I've always been bothered about having to statically declare the size[/color]
    of[color=blue]
    > a Java applet window (container?) in the calling HTML. I've always
    > wanted the moral equivalent of width=50% statement (of the window or
    > frame). I'm trying to use Javascript to do so.
    >
    > I can sort of get an example working in a Mozilla browser:
    >[color=green]
    > > <!-- This works on Mozilla only (and maybe netscape) -->
    > > <script language="Javas cript">
    > > document.write( "<applet code=MyApplet.c lass width="
    > > + window.innerWid th/2 + " height=" + window.innerWid th/2 +[/color]
    > "></applet> <br>" ); </script>
    >
    >
    > So the document.write statement produces a normal looking applet[/color]
    string[color=blue]
    > like this:
    >
    > <applet code=MyApplet.c lass width=252.5 height=252.5></applet>
    >
    > Which gets intepreted by the browser, kicking off the Java applet.[/color]
    But[color=blue]
    > as you resize the browser the alignment with other text in the html
    > window is funky. Also, in the above example, the window.innerWid th is
    > apparently from the Mozilla/Netscape DOM, not MS-IE's.
    >
    > Does anybody have any Javascript examples of how to dynamically[/color]
    presize[color=blue]
    > an applet to some percentage of the window/frame width? (that's mostly
    > portable)
    >
    > --
    > Ben in DC
    > PublicMailbox@b enslade.com (put 030516 anywhere in the subj to get[/color]
    thru)[color=blue]
    > "It's the mark of an educated mind to be moved by statistics"
    > Oscar Wilde
    >[/color]


    Comment

    • Put 030516 in email subj to get thru

      #3
      Re: Setting applet window size using javascript?

      Actually, I wasn't asking to resize anytime, just *pre* size one time based on the
      width of the web browser screen when the HTML page is loaded.

      I think I came up with a solution. Here's my slightly verbosely
      commented example, (also see www.benslade.com/DynAppletSize.html, note that I needed
      the Sun Java plugin for this to work with MS-IE 6 on Win XP. Why?)

      The first part which calculates the browser window dimensions has to come
      after the <body> declaration for certain web browsers:
      [color=blue]
      > <body>
      >
      > <script language="Javas cript">
      > // Calc window/screen width/height for Mozilla, NN>4, IE>4, IE6 in CSS1Compat mode (with a Formal DOCTYPE)
      > // from http://jibbering.com/faq/ with slight mods
      > // Note, this size calc must be in the body for IE 5+
      > // Exports global variables winWidth, WinHeight
      >
      > var d=document;
      > var winWidth, WinHeight;
      >
      > if (typeof window.innerWid th!='undefined' )
      > { winWidth = window.innerWid th; var winHeight = window.innerHei ght; }
      > else
      > if (d.documentElem ent && typeof d.documentEleme nt.clientWidth! ='undefined' && d.documentEleme nt.clientWidth! =0)
      > { winWidth = d.documentEleme nt.clientWidth; winHeight = d.documentEleme nt.clientHeight ; }
      > else
      > if (d.body && typeof d.body.clientWi dth!='undefined ')
      > { winWidth = d.body.clientWi dth; winHeight = d.body.clientHe ight; }
      > else { winWidth=150; winHeight=150; }
      > </script>[/color]

      then somewhere later in the same HTML document. This example sizes
      the Java applet to 1/2 the width of the web browser window:
      [color=blue]
      > <script language="Javas cript">
      > // Dynamically generate the HTML for an applet tag so that
      > // it can be initially sized based on the browser window size
      > // The round() func is needed for MS-IE on Mac & PC?
      >
      > document.write(
      > "<applet code=MySwitchTe st.class width=" +
      > Math.round(winW idth/2) +
      > " height=" + Math.round(winW idth/2) + "> </applet> <br>" );
      > document.write(
      > "applet code=MySwitchTe st.class width=" +
      > Math.round(winW idth/2) +
      > " height=" + Math.round(winW idth/2) + " /applet <br>" );
      > </script>[/color]



      VK wrote:[color=blue]
      > Inline applet (allocated on the web-page) doesn't support resize()
      > method: "once done, it's done".
      >
      > You can catch resize events from JavaScript and reload the page with
      > applet over and over on each resize. Evidently the current state of
      > applet will be lost.
      >[/color]

      --
      Ben in DC
      PublicMailbox@b enslade.com (put 030516 anywhere in the subj to get thru)
      "It's the mark of an educated mind to be moved by statistics" Oscar Wilde

      Comment

      Working...