Javascript in the address/URL bar

S

stepheno

I want to run some Javascript from the address bar (newlines included
for readability):

javascript:
location='http://www.example.com/page.html';
var num =
document.getElementById('content').getElementsByTagName('input')
[0].value;
document.write("Number is" + num);

In English:

1. Load a page
2. Get "123" from <div id="content"><input value="123" /></div>
3. Display the number ("123") to the user

I need to work when put in the address bar at any URL. However, it
only seems to work from 'http://www.example.com/page.html' (i.e. the
page I'm intending to load.)

Any ideas?
 
S

stepheno

Hi, thanks again for responding.

I simply need them to be able to click a link like

<a href="javascript:document.location('http://www.example.com/
page.html'); var num =
document.getElementById('content').getElementsByTagName('input')">Get
the number</a>

in email, or similar.

However, it only works when pasted to the address bar when
http://www.example.com/page.html is currently open. Otherwise, it
simply loads http://www.example.com/page.html.

I'll try and make an example URL this evening--unfortunately the
actual one is sensitive.

Thanks for your help, and patience,

Stephen

[0].value;
document.write("Number is" + num);
 
S

stepheno

You just don't grasp top-posting or not do you?

You just don't grasp basic English syntax or not do you? You just
don't grasp being polite or not do you? :)
Because that is what the script tells it to do. After the
document.location is set the script is discarded.

Ah, I see. Web design, not JS, is what I do so excuse my noobishness.

Thanks for your help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,823
Latest member
Nadia88

Latest Threads

Top