Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Setting onclick value for a link

12:37 am on Jun 22, 2013 (gmt 0)

Full Member

5+ Year Member Top Contributors Of The Month

joined:Sept 30, 2009
votes: 1

I'm trying to remove my inline javascript from my website and set all intrapage links (anchor links) on a page to run the 'doThis' function.

Unfortunately I can't figure out how to set the onclick value. I'm also wondering if this is the best way to detect intrapage links (this script would be running on lots of different websites).

for(i = 0; i < document.links.length; i++){
if(document.links[i].href.indexOf(window.location.host+window.location.pathname+'#') !== -1){
document.links[i].onclick = "return doThis(this.href)";}}
5:27 pm on June 22, 2013 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:May 23, 2005
votes: 0

Because I'm exhausted and a little lazy right now.