F
Fred!head
Hi,
I've banged my head for an hour researching and trying to figure out
what must be a simple thing in Javascript. If someone could help me or
point me in the right direction, I'd be grateful.
I want to add a link/image on 100 plus pages. Each link has to pass
the current page URL and page title contained in an H2 tag on the page
to a URL that'll process those values.
What I need is to output a URL like this:
http://www.mydomain.com/filename.php?u=CurrentPageURL&t=CurrentPageTitle
Sounds easy but I'm stuck on how to pull the value from the H2 tag in
the page. I've tried adding an id="header" value then calling it with:
document.getElementById('header')
However, I get 'null' as the screen output. Ideally I'd like to just
grab the value of the text between my <h2></h2> tags because it is
more efficient (less code).
I'm also able to grab the current URL with this javascript:
document.URL
Finally, ideally I want to pass this value to link dynamically so when
a user clicks the link it'll take them to the page. Can this be done
by passing a value to the href= value, like this:
var val = url;
loc = document.getElementById('link'); loc.href=val;
where the link is tagged id="link"? Or should I just have the
javascript output using document.write and then call the javascript
function inline?
Any ideas are appreciated. Thank you.
Tim
I've banged my head for an hour researching and trying to figure out
what must be a simple thing in Javascript. If someone could help me or
point me in the right direction, I'd be grateful.
I want to add a link/image on 100 plus pages. Each link has to pass
the current page URL and page title contained in an H2 tag on the page
to a URL that'll process those values.
What I need is to output a URL like this:
http://www.mydomain.com/filename.php?u=CurrentPageURL&t=CurrentPageTitle
Sounds easy but I'm stuck on how to pull the value from the H2 tag in
the page. I've tried adding an id="header" value then calling it with:
document.getElementById('header')
However, I get 'null' as the screen output. Ideally I'd like to just
grab the value of the text between my <h2></h2> tags because it is
more efficient (less code).
I'm also able to grab the current URL with this javascript:
document.URL
Finally, ideally I want to pass this value to link dynamically so when
a user clicks the link it'll take them to the page. Can this be done
by passing a value to the href= value, like this:
var val = url;
loc = document.getElementById('link'); loc.href=val;
where the link is tagged id="link"? Or should I just have the
javascript output using document.write and then call the javascript
function inline?
Any ideas are appreciated. Thank you.
Tim