Solved

getting document base using JSObject

Posted on 2001-06-06
3
463 Views
Last Modified: 2010-08-05
from my applet, I need to get the url of the html document using JSObject.
(I cannot use applet.getDocumentBase(), because it can be fooled with an html BASE tag).
for explorer I have a working solution, but in netscape, the following code does not work, href turns out to be null.


        JSObject window = getWindow(applet);
        JSObject location = (JSObject)window.getMember("location");
        Object href     = location.getMember("href");



0
Comment
Question by:omry_y
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
garyz31 earned 100 total points
ID: 6956809
This works on Internet Explorer and Navigator:

Java class code:

import java.applet.Applet ;
import netscape.javascript.* ;
import java.awt.* ;
import java.lang.String ;


public class AppTest  extends java.applet.Applet
{
private String pageURL ;
public netscape.javascript.JSObject js ;

public void init()
{     try
     {
     JSObject js = netscape.javascript.JSObject.getWindow(this) ;
     pageURL = js.getMember("location").toString() ;
     }
     catch(netscape.javascript.JSException e)
     {     e.printStackTrace() ;     }
}
public void paint(Graphics g)
{     g.drawString(pageURL, 10, 10) ;
}
}//class end

----------------------------------------------

HTML code:

<HTML>
<HEAD>
</HEAD>f
<BODY>
<Applet code="AppTest.class" width=400 height=200 id=OBJECT1
MayScript     VIEWASTEXT>
</Applet>
</BODY>
</HTML>
-------------------------------------------------

Hope this helps.


0
 
LVL 4

Author Comment

by:omry_y
ID: 7074041
sorry for the delay, I will check it shortly.
0
 
LVL 4

Author Comment

by:omry_y
ID: 7595532
since I don't need the info anymore, I did not check it, but I assume that its okay.

thanks.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
windows explorer path to command prompt 5 54
hibernate example issues from command prompt 10 50
How  can  i  resolve  HTTP Status 404 -? 8 42
jmss example java 2 23
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question