Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript bookmarklet go to URL and execute

Tags:

javascript

dom

I have a javascript like this, used i a bookmarklet:

window.location="URL"
document.getElementById('username-id').value = 'User'
document.getElementById('pwd-id').value = 'pass'
doLogin();

The problem is that javascript stops as soon as it hits the URL. How to make it go to a page and execute a script?

Any help would be greatly appreciated.

like image 874
Temikus Avatar asked Aug 18 '11 07:08

Temikus


1 Answers

I don't recommend browser extensions - they allow untrusted code to run in the context of trusted code. If you have a browser extension that loads a page and automatically enters your userID and password, what stops it from posting those credentials to a malicious site? Only you, and only if you've carefully read the source code.

To solve the problem above I've added bookmarklets to the favorites bar in my browser that require two clicks: 1. Click to navigate to the location 2. Click to fill the form

javascript: 
 var L='http://mysite.com/';
 if(location!=L)location=L;
 else{
  document.getElementById('username-id').value='User'; 
  document.getElementById('pwd-id').value = 'pass';
  document.close();
  doLogin(); 
 }

Good Luck!

like image 85
Rich Avatar answered Oct 27 '22 01:10

Rich