Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript Bookmarklet - Load page & fill form

Status
Not open for further replies.

pentesh

Technical User
Jan 10, 2012
9
IE
Hi

I wonder can someone help to suggest a way to interact with a webpage to perform a log in.

I have been working on the following javascript (very simple - to suit my ability!):

javascript:
window.open('void(0);
window.onload = function login() {
MainFrame.document.Form.username.value='username';
MainFrame.document.Form.password.value='password';
MainFrame.LoginClick();}();

With this I am getting the page loaded but it does not perform the log in.

When I separate the two parts out as follows I can run one bookmarklet to open the page and another to perform the login (and it works!) but I have no idea how to get both to run together in one bookmarklet.

javascript:
window.open('
javascript:
MainFrame.document.Form.username.value='username';
MainFrame.document.Form.password.value='password';
MainFrame.LoginClick();


Any ideas / suggestions very welcome. Thanks.
 
Hi

The bookmarklet code is executed in the current document's context. If it loads a new document, all the modifications it did get discarded together with the old document. You can not solve this easily with one bookmarklet. ( The complicated solution is to open an extra window and inject code to control the other one, then close the extra window. )

Personally I would prefer to use
[ul]
[li]One traditional bookmark to [ignore][/ignore][/li]
[li]One user script which on [ignore]example.com[/ignore] to check whether you are logged in and if not, then log in.[/li]
[/ul]

Note that the second step may require the installation of GreaseMonkey, TamperMonkey or similar browser extension.

Feherke.
[link feherke.github.com/][/url]
 
Thanks feherke.

Awkward as I am, I think I need to go down the more complicated route if it turns out to be possible. I am trying to automate a web based clock in / clock out system that we use in work. It never needs to check log in status.

Typically this is likely to be used by a relatively small number of users, but on a smartphone more than a desktop browser. Hence I was looking for an end to end as things like GreaseMonkey etc get complicated when it comes to mobile OSes.

Could you point me in the direction of any info on the solution opening a second window and I will see if I can make sense of it for my situation.

Thanks for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top