www.webdeveloper.com
Results 1 to 7 of 7

Thread: Passing variables to appletFrame using JavaScript

  1. #1
    Join Date
    Nov 2009
    Posts
    4

    Angry Passing variables to appletFrame using JavaScript

    I am a complete newbie to Javascript and I have a problem, which may be trivial. Please help.

    I have javascript which starts a Java applet and I want to pass data to the applet from another page.

    I want to retrieve the data of the variable 'port' at java_applet.html , which is originally set at info.html.

    Thanks for your help.


    Posting relevant details.

    Window (info.html) - runs javascript to get to java_applet.html.
    ======================
    .
    .
    <head>
    .
    .
    <script type="text/javascript">
    function startJavaApplet(){
    if (top.appFrame.appletFrame.location != "java_applet.html") {
    top.appFrame.appletFrame.location="java_applet.html";
    }else {
    top.appFrame.appletFrame.location.reload(true);
    }
    }
    </script>
    .
    .

    </head>
    <body onload="myOnLoad()"........>
    <form action="#"><input type="hidden" name="port" id="port"value="23"/></form>
    .
    .
    .
    <a href="javascript:void(0);" onclick="startJavaApplet();return false;"><b>My Java Applet</b></a>
    .
    .
    .
    </body>


    java_applet.html - invokes the java applet.
    ===================

    <head>
    .
    .
    </head>

    <body>
    <script type="text/javascript">
    <!--
    I want to access the value of port from info.html. However, the below approach is not working.
    -->
    var rport = window.parent.document.getElementById("port"); <== Not working, I get null.
    var _app = navigator.appName;
    if (_app == 'Netscape') {
    document.writeln("<embed code=\"myjavaapp.class\"");
    document.writeln("type=\"application/x-java-applet\"");
    document.writeln("archive=/html/myjavaapp_001.jar width=1000 height=100");
    document.writeln("RCINFO0=\"abcd\"");
    document.writeln("RCINFO1=\"21\"");
    document.writeln("RCINFO3=\"1\"");
    document.writeln("RCINFO6=\""+rport+"\"");
    .
    .
    .
    document.writeln("<\/embed>");
    }
    </script>
    </body>

  2. #2
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    top.document.getElementById

    edit:
    or actually, it looks like you're pages are all in the same domain, so just use top everywhere to refer to a common destination for each page.

    for example, top.port should reach the same variable on each frame's page.
    Last edited by rnd me; 11-06-2009 at 07:17 PM.

  3. #3
    Join Date
    Nov 2009
    Posts
    4
    Quote Originally Posted by rnd me View Post
    top.document.getElementById

    edit:
    or actually, it looks like you're pages are all in the same domain, so just use top everywhere to refer to a common destination for each page.

    for example, top.port should reach the same variable on each frame's page.
    It does not work. Following are the errors I get.

    top.port - undefined
    top.document.getElementById("port").value - Object required

  4. #4
    Join Date
    Nov 2009
    Posts
    4
    I am posting complete code now.

    info.html
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//Dtd HTML 4.01 Transitional//EN">
    <html>
    <head>
    <script type="text/javascript">
    function myOnLoad(){
    }
    function startJavaApplet(){
    if (top.location != "java_applet.html") {
             top.location="java_applet.html";
          }else {
             top.location.reload(true);
          }
    }
    </script>
    </head>
    
    <body onload="myOnLoad()" style="overflow: auto;" class="body-flush-fit">
    <form name=myform action="#"><input type="hidden" name="port" id="port"value="23"/></form>
    <a href="javascript:void(0);" onclick="startJavaApplet();return false;"><b>My Java Applet</b></a>
    </body>
    
    </html>
    java_applet.html
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//Dtd HTML 4.01 Transitional//EN">
    <html>
    <head>
    <script type="text/javascript">
    function myOnLoad(){
    alert("Loaded java_applet.html");
    }
    </script>
    </head>
    
    <body>
    <script type="text/javascript">
    var pr = top.port;  //Fails
    alert("port " + pr);
    </script>
    </body>
    
    </html>

  5. #5
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    i don't see any frames, is this simply a redirect or something?
    it seems like info.html should be in a frame to me.

    if you are simply changing the page location, there's no way to communicate to a page that doesn't exist at the time, so top won't help.


    if that's the case, use name:

    Code:
    onclick="window.name=23; startJavaApplet();return false;"

    then you can change:
    Code:
    var pr = top.port;  //Fails
    alert("port " + pr);
    to
    Code:
    var pr = top.name;  //Fails
    alert("port " + pr);

  6. #6
    Join Date
    Jan 2009
    Posts
    3,346
    In the first post you have:
    var rport = window.parent.document.getElementById("port");
    Which should be:
    Code:
    var rport = window.parent.document.getElementById("port").value;

  7. #7
    Join Date
    Nov 2009
    Posts
    4

    resolved

    This works.
    Thank you very much rnd me.
    info.html is indeed part of a frame.

    Quote Originally Posted by rnd me View Post
    i don't see any frames, is this simply a redirect or something?
    it seems like info.html should be in a frame to me.

    if you are simply changing the page location, there's no way to communicate to a page that doesn't exist at the time, so top won't help.


    if that's the case, use name:

    Code:
    onclick="window.name=23; startJavaApplet();return false;"

    then you can change:
    Code:
    var pr = top.port;  //Fails
    alert("port " + pr);
    to
    Code:
    var pr = top.name;  //Fails
    alert("port " + pr);
    Last edited by Limraj; 11-07-2009 at 09:13 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles