Solved

getting document base using JSObject

Posted on 2001-06-06
3
464 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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
arguments to jar 5 39
going to wrong jsp page 2 47
ejb message driven bean mdb creation steps 2 35
Fast way to search item into Java Array (Rhino compatible) 2 38
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

756 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