aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Renaming the title bar iin a browser using html Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Renaming the title bar iin a browser using html" Watch "Renaming the title bar iin a browser using html" New topic
Author

Renaming the title bar iin a browser using html

Maja Gralewska
Ranch Hand

Joined: Sep 26, 2008
Posts: 92
Hi,

When i run my applet, i would like the browser to dynamically display the current job number that has been selected in the title bar of the browser, is there a way to do this using html an JavaScript?

eg: MyProgram Job 2337 - Browser name

Thanks


Potrzeba jest matka wynalazków
steve claflin
Ranch Hand

Joined: Dec 04, 2008
Posts: 54
try document.title = "new title";
Maja Gralewska
Ranch Hand

Joined: Sep 26, 2008
Posts: 92
Thanks,

That works great, but i need it to be dynamically set getting the variable from the program and i haven't got a clue where to even start, here is my current code:



Any suggestions will be greatly appreciated, thanks.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
You should have an error message and it should state your issue.

With firefox use the JavaScript console, with IE click the error icon in the status bar.

It is a pretty simple mistake.

Eric
Maja Gralewska
Ranch Hand

Joined: Sep 26, 2008
Posts: 92
Hi,

I checked my log but there weren't any errors, maybe im looking in the wrong log? is there a standers place where the log is? im using fire fox and the only log i know of is the server log, & java console?? I also took out the code that made it scroll so it now looks like:



I have not done html or java script before, so i don't really know if what i am doing is possible.

Thanks for all your help guys.
Maja Gralewska
Ranch Hand

Joined: Sep 26, 2008
Posts: 92
The </APPLET> tag is there just missed it when i used copy and paste. thanks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42292
    
  64
JavaScript can't use variables that are declared inside of the applet. And actually, you don't need JavaScript for this - the applet can manipulate the HTML DOM through the Common DOM API.


Ping & DNS - my free Android networking tools app
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Tools-->Error Console.

With your original example it ran if you declared your speed variable.

Eric
Maja Gralewska
Ranch Hand

Joined: Sep 26, 2008
Posts: 92
Hey,

I read Common DOM API., and although it helped me with the Firefox setting, i am still very confused about how to use dom, java and html together, i have looked at some other web sites to see if i would find anything that would be able to make me understand better, eg: www.webdeveloper.com/forum/showthread , www.stylusstudio.com/xsllist/200108/post50350.html. Is dom normal java? Is it used like a session bean? eg: applet.java --> dom --> applet.html? Or is used in the applet.java class and when the applet is run it sends the variable to the html.

Sorry for all the questions.

//thanks Eric that got it moving

Thanks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42292
    
  64
The sylusstudio URL links to something about XSLT - not sure how you got there, but you're on the wrong track; XSLT has nothing to do with this.

The article about the Common DOM API has an example that shows how the applet can retriev the HTML page title; from there it should be easy to figure out how the applet might set the title.

Or does your last comment mean you've been successful with the JavaScript approach?
Maja Gralewska
Ranch Hand

Joined: Sep 26, 2008
Posts: 92
No, that was the speed value.

I read that example a couple of times but i can't seem to grasp how dom is used? Is it in the java class where the applet code is? Or is it a class by itself that is used like a session bean? At the moment i am reading just java 2 - a program that uses a dom parser but i still can't seem to understand how it connects to html?

Thanks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42292
    
  64
Take a look at listing 2 in that article. See how it imports the org.w3c.dom.html.* classes? That's the HTML DOM. It's a fairly simple example, so the only code that actually uses the page DOM is this:

It retrieves the HTMLDocument object (the root DOM object of an HTML page) for the HTML page in which the applet lives, and uses that to get the page title. Here's a little hint: that object also has a "setTitle(String)" method :-)
[ December 09, 2008: Message edited by: Ulf Dittmer ]
Maja Gralewska
Ranch Hand

Joined: Sep 26, 2008
Posts: 92
lol thanks , im trying to get the example to work first, but whenever it reaches the following line:



It gives me this error:



Is there maybe something i'm missing in my html code? does the
import org.w3c.dom.html.*; have to be in the html or should it be removed?

Thanks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42292
    
  64
Which JVM version from which vendor are you using? I think the Common DOM API was introduced with the Java Plugin that came with Java 5. So if you're using an earlier JVM this may not work.
Maja Gralewska
Ranch Hand

Joined: Sep 26, 2008
Posts: 92
Its:

C:\>jview
Microsoft <R> Command-line Loader for Java Version 5.00.3805

So it should work fine?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42292
    
  64
Ouch! You're using the age-old obsolete Microsoft JVM. Run -don't walk- to get rid of it; this page has removal instructions. Then download and install a JVM from java.sun.com; you'll be much happier :-)
Maja Gralewska
Ranch Hand

Joined: Sep 26, 2008
Posts: 92
lol my poor computers feelings are hurt! :-) I'm not allowed to hey, the whole system that the program runs on is based on the same version on everyone's pc, they tried to update java on one of the p.c and the system when mad and when they got it running the new code didn't work... So ya.

Any Any Any suggestions?

Thanks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42292
    
  64
An alternative way for applets to communicate with JavaScript is called LiveConnect; see here for some related links. That used to work with the MS JVM, but I'm not sure if it still does. Try the mozilla.org test pages linked from that page to see if it works for you. If it does, then you can call a JavaScript method that changes the page title from within the applet (and pass the new title as a parameter).
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Originally posted by Maja Gralewska:
lol my poor computers feelings are hurt! :-) I'm not allowed to hey, the whole system that the program runs on is based on the same version on everyone's pc, they tried to update java on one of the p.c and the system when mad and when they got it running the new code didn't work... So ya.

Any Any Any suggestions?

Thanks


Are you running Netscape 4 and IE 5.5 also. lol [a joke]

Eric
Maja Gralewska
Ranch Hand

Joined: Sep 26, 2008
Posts: 92
I tried that now and it's still not working, but i'm not getting any error messages either: here is all my code... i'm most-probably doing something really stupid but anyways here's my code:

Java class where applet is in:



This is my html code:



Thanks a ton
Maja Gralewska
Ranch Hand

Joined: Sep 26, 2008
Posts: 92
lol, what can i say... guess its just my poor pc's destiny to be mocked!!
....you betta just be mocking my pc lol:-)
[ December 09, 2008: Message edited by: Maja Gralewska ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42292
    
  64
If fetchJobReference takes a String argument then you better pass a String to it.

I think it's safer to use "document.applets[0]" than "document.DynamicApplet".
Maja Gralewska
Ranch Hand

Joined: Sep 26, 2008
Posts: 92
hey:-)

Tried what you suggested, still not working & no errors, but now if i put the function code & the code that renames the title bar in the same script it won't rename the title bar even to the default value...

Is it possible to maybe write the variable to destination folder and then call it from the destination folder using html?

Thanks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42292
    
  64
It's hard to say what might be going wrong with code we don't know.

What do you mean by "destination folder" in the context of a web page?
Maja Gralewska
Ranch Hand

Joined: Sep 26, 2008
Posts: 92
Hey

I meant an actual drive with a created folder to where i write the data??
But i don't really see how that could work efficiently?

Its all good tho, tried it on my laptop(has a sun JVM) and it worked hundreds, it just refuses to work on a windows JVM(wierd) so they said i can just leave the default title value for the time being...

Thanks a million tho, you guys really helped me loads

Thanks

[ December 10, 2008: Message edited by: Maja Gralewska ]
[ December 10, 2008: Message edited by: Maja Gralewska ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Renaming the title bar iin a browser using html