Adding onclick javascript code to links

Hi, some of our customers use client-side statistics tools that depend on running javascripts to collect statistics on the web site traffic. This is great for counting page views as the javascript can be added to the page, but when it comes to counting downloads of pdf documents etc., the suggested approach is to run the javascript in the onclick attribute of the link. For download lists created as usercontrols I can add the necessary javascript code in the user control, but if they want to count downloads published from inside the XHTML editors, they have to switch to HTML mode and manually insert the javascript... Can anyone think of a way to automatically insert this code into published downloads and external links? I thought of doing something with the link editor but I read elsewhere that it's not meant to be extended... tom
Jun 25, 2007 20:17
Hi Thomas! I have done this (extended the link dialog), and I can say that its _not_ an easy task (even having the sourcecode available). I did it by using a shadowed "Util/_dialogs/HyperlinkProperties.aspx" where I added a new input control to the dialog. I then modified the script to combine the url with my "extra input" to form one url in the form "http://<<original url>>$$CSTRACK=<<extra input>>" Then I also needed an editor plugin to run some specialized javascript (overriding the scripts/HyperlinkProperties.js) to look for url's having this "$$CSTRACK=" parameter, and if found, extract that extra input and put it into a "onclick=" attribute of the A-element. This approach would not be ideal in that it requires modifications to episerevr core files. Even though it can be done through shadowed files, there's always the potential problem with upcoming service releases. In my opinion, I think you should consider some other alternative: *) create an editorplugin to modify an existing A-element. This requires however the editor (person) to take an extra step when creating such links. *) derive a new Property from PropertyLongString and insert the appropriate onclick-javascript upon submitting by parsing the htmlcode server side. (this would be the best option if the onclick-generation could be totally automated and requires no extra user input). *) create an editorplugin where you take care of inserting the links yourself. probably the "best" solution if extra user input is needed, but requires a lot of coding... If you need more details, send me an email and I'll try to "package" the stuff together for you. Regards, Johan Olofsson EPiServer AB
Jun 26, 2007 9:30
I've fiddled with both the link editor and the image editor and extended it quite a bit. It's not easy like Johan says, but definately not impossible. I recently made a change to the link-editor and added a style dropdown for selecting a link css style, like you can do with text in the editor (styles are read from the css just like "EditMenuName"). It took about 4-5 hours. If you document the changes it wouldn't take long to reproduce in case you need to upgrade and you're unlucky enough to have the link editor replaced by an updated one. It would think it takes about the same time to create a hack this way as making a routine that parse the saved text and look for links etc. Parsing text could be affected by an updated aswell if the link format is changed in some way.
Jun 27, 2007 2:43
Jun 27, 2007 10:23
One easy way would be to add client script and attach a method to the onclick event of all anchors. I have done similar things on many different sites and for different purposes. This example might lead you in the right direction. The code below is from that I made last winter. @ you can se the script in action. You need also need the 'eol.js' that can be found @ or more specific @ Regards, HAXEN // --- var arrQandAs = new Array(); function initFAQ() { var arrQuestions = getElementsByClassName(document, "span", "question"); var oQandASection; for(var i=0; i
Jun 27, 2007 12:03
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.