www.webdeveloper.com
Recent Articles
  • Finding Slow Running Queries in ASE 15
  • A More Advanced Pie Chart for Analysis Services Data
  • Adobe AIR Programming Unleashed: Working with Windows
  • Performance Testing SQL Server 2008's Change Data Capture Functionality
  • The ABC's of PHP: Introduction to PHP
  • How to Migrate from BasicFiles to SecureFiles Storage
  • Why the Twitter Haters Are Wrong
  • User Personalization with PHP: Beginning the Application
  • Whats in an Oracle Schema?
  • Lighting Enhancement in Photoshop
  •  

    Go Back   WebDeveloper.com > Client-Side Development > JavaScript

    JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...)

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1  
    Old 11-06-2009, 06:02 PM
    Limraj Limraj is offline
    Registered User
     
    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>
    Reply With Quote
      #2  
    Old 11-06-2009, 07:14 PM
    rnd me's Avatar
    rnd me rnd me is offline
    working on the chain...
     
    Join Date: Jul 2008
    Location: urbana, il
    Posts: 1,275
    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.
    Reply With Quote
      #3  
    Old 11-06-2009, 07:44 PM
    Limraj Limraj is offline
    Registered User
     
    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
    Reply With Quote
      #4  
    Old 11-06-2009, 07:48 PM
    Limraj Limraj is offline
    Registered User
     
    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>
    Reply With Quote
      #5  
    Old 11-06-2009, 08:36 PM
    rnd me's Avatar
    rnd me rnd me is offline
    working on the chain...
     
    Join Date: Jul 2008
    Location: urbana, il
    Posts: 1,275
    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);
    Reply With Quote
      #6  
    Old 11-06-2009, 09:47 PM
    criterion9 criterion9 is offline
    Registered User
     
    Join Date: Jan 2009
    Posts: 997
    In the first post you have:
    Quote:
    var rport = window.parent.document.getElementById("port");
    Which should be:
    Code:
    var rport = window.parent.document.getElementById("port").value;
    Reply With Quote
      #7  
    Old 11-07-2009, 09:11 AM
    Limraj Limraj is offline
    Registered User
     
    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.
    Reply With Quote
    Reply

    Bookmarks


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is Off
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 08:00 AM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy

    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.