Solved

getting document base using JSObject

Posted on 2001-06-06
3
460 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Protect jar file - windows app 2 53
java.io.BufferedReader   readLine()  //returns the entire file ? 4 73
jboss wildfly 10.1 10 92
Running JavaFX on JDeveloper 12C 1 32
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This video teaches viewers about errors in exception handling.

773 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