Reputation: 14953
How does Javascript work in the browser address bar?
To be more specific: how can I make a script that goes to a web site and clicks a button on that site? Not maliciously, of course, I'd like to be able to do this for personal use.
Upvotes: 0
Views: 455
Reputation: 396
What you are talking about is called a "bookmarklet", and depending on exactly what you are talking about, you could probably accomplish it via a bookmarklet... but it may be more trouble than it's worth.
Bookmarklets are generally used to make simple modifications on the page you are currently viewing. For example, a book-marklet may hide all the pictures on a page.
You can write bookmarklets that interact with another page, for a complex example see the jQUeryUI boomarklet: here
However, generally the type of thing you are talking about would be accomplished via something like a Grease Monkey/User Script and/or "extension". I would recommend going that route instead.
Upvotes: 0
Reputation: 1937
View the source code of the page and find the reference to the button you'd like to click. You're looking for something like this:
<input type="submit" value="Click Here" id="theButtonId"/>
Then you can type in the address bar:
javascript:document.getElementById("theButtonId").click();
To navigate to a website, do this:
javascript:window.location='http://www.google.com';
Upvotes: 1
Reputation: 12545
JavaScript in the address bar is evaluated just like any JavaScript.
On your second point, you don't. That's called cross site scripting or XSS. You can't have JavaScript from one site modify another site.
You could potentially write an extension to your web browser that will accomplish what you want.
Upvotes: 3