trip008vk
asked on
is it possible to load a web page into a browser, and then shut the browser when loaded?
I would like to use Java to open firefox and load a web page into it. once the page finishes loading, i would like to end firefox. how would i do this?
opening firefox from java is easy, and executing a kill command to stop firefox is easy too. but how would i find out when the page finishes loading?
opening firefox from java is easy, and executing a kill command to stop firefox is easy too. but how would i find out when the page finishes loading?
Why are you trying to do this? If you simply want to hit a URL, you can easily do that within Java (I can give some sample code for that if you like). If you are firing up Firefox because you want that as your user-agent, it's easy to set that programmatically too. Then you don't have to mess with launching/killing Firefox.
ASKER
i'm doing this because i need to run some javascript code in firefox, and then have the browser close...
Have you looked into the javax.script.ScriptEngine functionality? I don't know if this will necessarily solve your problem, but it might be worth considering.
http://download.oracle.com/javase/6/docs/technotes/guides/scripting/programmer_guide/index.html
http://download.oracle.com/javase/6/docs/technotes/guides/scripting/programmer_guide/index.html
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ksivananth, could you be a little more clear as to how to use JDIC to solve my issue?
thanks!
thanks!
look at the downloadCompleted event fired when the page loading completed...
if you particular about the particular javascript function executed, you may want to change the status message from the javascript function which you can listen through JDIC. once you notified the status change event with that particular string you printed through javascript function, you can close JDIC!
if you particular about the particular javascript function executed, you may want to change the status message from the javascript function which you can listen through JDIC. once you notified the status change event with that particular string you printed through javascript function, you can close JDIC!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
and also https://jdic.dev.java.net/#demos
ASKER
thanks
I dont think you can do this in java. Since after starting the browser, for your java program the task is completed, and control is no longer with your java program. After which firefox process cannot send any signal or interrupts to your java program.
You need to check if there is any command, which can tell given a browser's PID, what are the pages loaded and their status