I have a link and I need it to do two thing when it's clicked. First, it tracks the h it using the google tracking code, and the next is that it opens a new window.
I tried:
onclick="javascript: pageTracker._trackPageview('/Ads/MMA_Front_Page'); window.open(this.href, '_blank'); return false;"
But it didn't work, it didn't open a new window.
Did I do something wrong with the code or do I need to create a javascript method and call that?
Thanks
Edit: I am trying with functions, but it wont work. Can you help me please?
Here is the function:
<script type="text/javascript">
function openAd(adType) {
pageTracker._trackPageview(adType);
window.open(this.href, '_blank');
return false;
}
</script>
And the part where i call it:
onclick="openAd('/Ads/MMA_Front_Page')"
It seems only the first part is working "pageTracker._trackPageview(adType);" and the rest is being ignored.
I have a link and I need it to do two thing when it's clicked. First, it tracks the h it using the google tracking code, and the next is that it opens a new window.
I tried:
onclick="javascript: pageTracker._trackPageview('/Ads/MMA_Front_Page.'); window.open(this.href, '_blank'); return false;"
But it didn't work, it didn't open a new window.
Did I do something wrong with the code or do I need to create a javascript method and call that?
Thanks
Edit: I am trying with functions, but it wont work. Can you help me please?
Here is the function:
<script type="text/javascript">
function openAd(adType) {
pageTracker._trackPageview(adType);
window.open(this.href, '_blank');
return false;
}
</script>
And the part where i call it:
onclick="openAd('/Ads/MMA_Front_Page.')"
It seems only the first part is working "pageTracker._trackPageview(adType);" and the rest is being ignored.
Share Improve this question edited Dec 10, 2011 at 21:14 TheGateKeeper asked Dec 10, 2011 at 18:10 TheGateKeeperTheGateKeeper 4,53023 gold badges68 silver badges105 bronze badges 1-
4
What's wrong with creating functions inside your
<script>
tag? – César Commented Dec 10, 2011 at 18:11
2 Answers
Reset to default 3You should really use functions inside your <script>
tag but, try without the javascript:..
. like:
onclick="pageTracker._trackPageview('/Ads/MMA_Front_Page.'); window.open(this.href, '_blank'); return false;"
onclick="do_something();"
<script type="text/javascript">
function do_something(){
pageTracker._trackPageview('/Ads/MMA_Front_Page.');
window.open(this.href, '_blank');
return false;
}
</script>
You have included answer in your question. It will be better to create a function for multiple statement.