Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2008-10-02 18:49:46

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,330
Website Mastodon

Re: [textile] Javascript in links?

Sorry, I missed a few single quotes around 'http://' when I posted. See revised code above.

Offline

#14 2008-10-02 18:58:17

lee
Member
From: Normandy, France
Registered: 2004-06-17
Posts: 831

Re: [textile] Javascript in links?

Hate to say this but it’s still not picking up the external links.

Offline

#15 2008-10-02 19:00:24

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,330
Website Mastodon

Re: [textile] Javascript in links?

So this is where it ends without real access to the site…

Offline

#16 2008-10-02 21:20:15

lee
Member
From: Normandy, France
Registered: 2004-06-17
Posts: 831

Re: [textile] Javascript in links?

Thanks for all the help Robert.

Offline

#17 2008-10-02 22:41:23

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: [textile] Javascript in links?

Well, prehaps wet’s code:

$("a[href^='http://']").addClass('external');

Should really be:

$("a[@href^=http://]").addClass('external');

And now it should add the class ;)

Last edited by Gocom (2008-10-02 22:45:59)

Offline

#18 2008-10-03 04:16:09

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,330
Website Mastodon

Re: [textile] Javascript in links?

This is what we came up with to add a new class to all links which do not point to the own site (www.example.com in this case):

<script type="text/javascript">
$(document).ready( function() {
$("a[href^='http://']").each(function(){if($(this).attr('href').indexOf('http://www.example.com') == -1) $(this).addClass('external');})
$('a.external').click(function(){pageTracker._trackPageview(this.href);})
})
</script>

There’s certainly room for improvement, but it works as intended.

Offline

#19 2008-10-03 05:59:28

lee
Member
From: Normandy, France
Registered: 2004-06-17
Posts: 831

Re: [textile] Javascript in links?

In case it’s not clear, the javascript added to the links is used by Google Analytics to track clicked outbound links.

More info here at Google

Offline

Board footer

Powered by FluxBB