Setting applet window size using javascript?

Discussion in 'Javascript' started by Put 030516 in email subj to get thru, Oct 24, 2003.

  1. 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:

    > <!-- This works on Mozilla only (and maybe netscape) -->
    > <script language="Javascript">
    > document.write( "<applet code=MyApplet.class width="
    > + window.innerWidth/2 + " height=" + window.innerWidth/2 +

    "></applet> <br>" ); </script>


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

    <applet code=MyApplet.class 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.innerWidth 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
    (put 030516 anywhere in the subj to get thru)
    "It's the mark of an educated mind to be moved by statistics"
    Oscar Wilde
     
    Put 030516 in email subj to get thru, Oct 24, 2003
    #1
    1. Advertising

  2. Put 030516 in email subj to get thru

    VK Guest

    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 <> wrote
    in message news:R8gmb.984$...
    > 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:
    >
    > > <!-- This works on Mozilla only (and maybe netscape) -->
    > > <script language="Javascript">
    > > document.write( "<applet code=MyApplet.class width="
    > > + window.innerWidth/2 + " height=" + window.innerWidth/2 +

    > "></applet> <br>" ); </script>
    >
    >
    > So the document.write statement produces a normal looking applet

    string
    > like this:
    >
    > <applet code=MyApplet.class 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.innerWidth 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
    > (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, Oct 24, 2003
    #2
    1. Advertising

  3. 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:

    > <body>
    >
    > <script language="Javascript">
    > // 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.innerWidth!='undefined')
    > { winWidth = window.innerWidth; var winHeight = window.innerHeight; }
    > else
    > if (d.documentElement && typeof d.documentElement.clientWidth!='undefined' && d.documentElement.clientWidth!=0)
    > { winWidth = d.documentElement.clientWidth; winHeight = d.documentElement.clientHeight; }
    > else
    > if (d.body && typeof d.body.clientWidth!='undefined')
    > { winWidth = d.body.clientWidth; winHeight = d.body.clientHeight; }
    > else { winWidth=150; winHeight=150; }
    > </script>


    then somewhere later in the same HTML document. This example sizes
    the Java applet to 1/2 the width of the web browser window:

    > <script language="Javascript">
    > // 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=MySwitchTest.class width=" +
    > Math.round(winWidth/2) +
    > " height=" + Math.round(winWidth/2) + "> </applet> <br>" );
    > document.write(
    > "applet code=MySwitchTest.class width=" +
    > Math.round(winWidth/2) +
    > " height=" + Math.round(winWidth/2) + " /applet <br>" );
    > </script>




    VK wrote:
    > 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.
    >


    --
    Ben in DC
    (put 030516 anywhere in the subj to get thru)
    "It's the mark of an educated mind to be moved by statistics" Oscar Wilde
     
    Put 030516 in email subj to get thru, Oct 25, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fuzzyman
    Replies:
    4
    Views:
    641
    Eric Brunel
    Jan 19, 2004
  2. crazytazo
    Replies:
    3
    Views:
    1,258
    Daniel Pitts
    Oct 7, 2008
  3. Greg Smith
    Replies:
    0
    Views:
    313
    Greg Smith
    Feb 16, 2009
  4. Russell
    Replies:
    2
    Views:
    290
    Russell
    Sep 13, 2004
  5. jodleren

    Getting picture size/setting window size

    jodleren, Feb 14, 2007, in forum: Javascript
    Replies:
    2
    Views:
    159
    jodleren
    Feb 15, 2007
Loading...

Share This Page