0

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.

Brighid McDonnell
4,3734 gold badges39 silver badges64 bronze badges
asked Apr 22, 2010 at 0:47
2
  • 6
    Javascript is spelled with an i and has nothing to do with caves or vampires. (Except where IE is concerned) Commented Apr 22, 2010 at 0:51
  • 1
    BTW, you really shouldn't tag (almost) all your questions with the 'help' tag, that's not needed (and pollutes the 'help' tag) Commented Apr 22, 2010 at 0:57

4 Answers 4

4

You want to make a bookmarklet.

answered Apr 22, 2010 at 0:54
Sign up to request clarification or add additional context in comments.

Comments

3

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.

answered Apr 22, 2010 at 0:50

4 Comments

i've had people tell me to put malicious javascrypt in my browser that would have forced me to go to a website and click things without my consent.
@David: Huh, what? And you listen to them?
Yes, but you need to paste it in the address bar first (or a in bookmark)
No, you haven't had JavaScript code from one site modify or interact with another site. You may have had code that directed your browser to a malicious site.
1

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';
answered Apr 22, 2010 at 1:00

Comments

0

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.

answered Apr 22, 2010 at 1:00

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.