Reputation: 103
i open a web page through IE from java code as follows:
Runtime.getRuntime().exec(url).
My web page displays authentication screen with user name and password (pretty much the same user and password for all the users).
in addition, i have created java script that populates the user name and password automatically as hard coded. and it works fine if i run it manually while the focus is on my web page.
Is there any possibility to run the script through the above command? i just want to open the page and that the user & password will be populated...
Thanks!
Upvotes: 0
Views: 194
Reputation: 103807
Firstly, your method of launching the browser is rather flaky. What you're currently doing is running the URL as if it were a command, i.e. the name of a process to run. This is similar to typing it at a command prompt or the Windows Run... dialog. Fortunately in this case, Windows interprets an attempt to execute an HTTP URL by launching IE with that URL, but that's not likely to be consistent in other environments. A better approach would be to use Desktop.browse, which specifically launches the URL in the default browser.
As to your question itself, it's very unlikely this is possible. You're spawning a new (IE) process, which is completely separate from your Java process. Without some form of inter-process communication, Java won't be able to send commands to IE on the fly. The only possible way this might work is by passing arguments to the command that are interpreted by the new process. To my knowledge however there are no command-line arguments that will cause IE to run an arbitrary piece of JS once a page is loaded.
Upvotes: 2
Reputation: 454
To run code when the page loads. Put it in an onload function.
window.onload = function(){
// your javascript code here
}
Upvotes: -1