homepage Welcome to WebmasterWorld Guest from 54.242.126.9
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Setting onclick value for a link
ocon

5+ Year Member



 
Msg#: 4586618 posted 12:37 am on Jun 22, 2013 (gmt 0)

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)";}}

 

drhowarddrfine

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 4586618 posted 5:27 pm on Jun 22, 2013 (gmt 0)

Because I'm exhausted and a little lazy right now.
https://developer.mozilla.org/en-US/docs/Web/API/element.onclick

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved