tags:

views:

40

answers:

4

How does javascrypt work in the adress bar? more spacificaly how do i make a scrypt that goes to a website and clicks a button on that website? (not maliciously, i'd like to be able to do this for personal use.

+2  A: 

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.

Jonathon
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
@David: Huh, what? And you listen to them?
Marcel Korpel
Yes, but you need to paste it in the address bar first (or a in bookmark)
SLaks
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.
Jonathon
+3  A: 

You want to make a bookmarklet.

SLaks
+1  A: 

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';
Drew
A: 

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.

MisterMister