Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Redefining onClick Issue
Old 10-14-2010, 08:28 PM Redefining onClick Issue
The_Anomaly's Avatar
Extreme Talker

Posts: 216
Location: Boston, Ma
Trades: 0
I am working on some code to redefine onClick but have run into an issue and have no idea where to go from here. The issue arises when there is already something defined within the html for the onClick handler.

The following if statement would take a link, pull out the existing onclick info, then add the new info. There is a bunch of text stripping thats needs to be done in order to get rid of the IE and FF junk that is already showing up in the onClick.

The problem is, after I define everything the output ends up showing the actual variable rather than the contents of the variable. There must be some data type I could convert this to in order to get it working, but I really have no idea what it would be:

Output as of now
Code:
function(){ return existingClick }
I know that this should work, for the links that do not contain the existing onclick info I can just use the following (which does work):

Code:
document.links[i].onclick = function(){ return openQuickWindow(this.href);};
This is the code I am using:

Code:
if (typeof document.links[i].onclick == "function"){ // if 2

                  //define existing onclick and convert to string
                  var existingClick = String(document.links[i].onclick);
                  
                  //define var for new function to be added
                  var newlink = "openQuickWindow(this.href);";
                  
                  //remove the firefox and IE extras
                  existingClick = existingClick.replace("function","");
                  existingClick = existingClick.replace("onclick(event)","");
                  existingClick = existingClick.replace("{","");
                  existingClick = existingClick.replace("anonymous()","");
                  existingClick = existingClick.replace("}","");
                  
                  //trim trailing spaces
                  existingClick = existingClick.replace(/^\s*/,"").replace(/\s*$/,"");
                  
                  //make sure the existing onclick ends with a semicolon to avoid functions running together
                  if(existingClick.charAt(existingClick.length - 1) !== ";"){
                    existingClick = existingClick + ";";
                  }
                  
                  // add new function to existing functions string
                  existingClick = existingClick + newlink;
                  
                  //create new onclick event
                  document.links[i].onclick = function(){ return existingClick }
                  
                  //debuging
                  alert(document.links[i].onclick); 
                }
The_Anomaly is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-15-2010, 02:46 PM Re: Redefining onClick Issue
The_Anomaly's Avatar
Extreme Talker

Posts: 216
Location: Boston, Ma
Trades: 0
Well this can be ignored. I used an eventlistener like I should have and can just ignore the onclick values.
The_Anomaly is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Redefining onClick Issue
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.09599 seconds with 12 queries