document.write and onclick

  • HDgirlMD
  • Born
  • Born
  • HDgirlMD
  • Posts: 1

Post 3+ Months Ago

Can anyone help me with this javascript code?

JAVASCRIPT Code: [ Select ]
document.write('<A onclick="javascript&#058;urchinTracker(\'/intranet/outgoing/docdownloads/' + docTitle + ');" href="' + ktOpenLink + docID + '">' + displayName + '</A>');

The href part works as it launches the document but the onclick part appears to not work. I am trying to capture downloaded documents from a remote sight to track the clicks in Urchin.

Thanks in advance,

Moderator Remark: Please use [code][/code] tags around code snippets
  • joebert
  • Genius
  • Genius
  • User avatar
  • Posts: 13511
  • Loc: Florida

Post 3+ Months Ago

What's happening is that when you click the link, the browser navigates away from the current page before "urchinTracher()" has a chance to do it's thing.

It's possible to tell the browser to wait for your event handler to resolve before navigating away from the page. This is done by using the "return" statement within your event handler.

Instead of "onclick='urchinTracker...", you will use "onclick='return urchinTracker...". to eliminate the result of urchinTracker dictating whether your visitor goes anywhere or not, you'll use a "ternary" operator with both paths leading to "true".

HTML Code: [ Select ]
<a onclick="return urchinTracker(...) ? true : true;">

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 28 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum

© 1998-2017. Ozzu® is a registered trademark of Unmelted, LLC.