|
|||||||
| JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...) |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
||||
|
||||
|
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.
__________________
libs: mini (updated) ASPmini myIO (new) dnd tmpl8 apps: snippets blog photos crypto image editor crapplets: json browse json view compressor time grads Last edited by rnd me; 11-06-2009 at 07:17 PM. |
|
#3
|
|||
|
|||
|
Quote:
top.port - undefined top.document.getElementById("port").value - Object required |
|
#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>
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
|
||||
|
||||
|
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);
Code:
var pr = top.name; //Fails
alert("port " + pr);
__________________
libs: mini (updated) ASPmini myIO (new) dnd tmpl8 apps: snippets blog photos crypto image editor crapplets: json browse json view compressor time grads |
|
#6
|
|||
|
|||
|
In the first post you have:
Quote:
Code:
var rport = window.parent.document.getElementById("port").value;
|
|
#7
|
|||
|
|||
|
This works.
Thank you very much rnd me. ![]() info.html is indeed part of a frame. Quote:
Last edited by Limraj; 11-07-2009 at 09:13 AM. |
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|