Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

getting document base using JSObject

Posted on 2001-06-06
3
Medium Priority
?
472 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 400 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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 will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses

916 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