Tuesday, September 20, 2011

target "_blank" opens two windows (Means link open in New window as well as same window)

step1)suppose you add html code in a page of drupal using FCK EDITOR , In that one facebook link is there and after clicking that link,that link open in new window as well as same window.
Here is the code :
<a target="_blank" href="http://www.facebook.com/pages/The-Ideal-School-of-Manhattan/156013431088499">facebook</a>
step2:This problem occurs from "Google Analytic" module

step3:To solve this problem U have three ways:

 1st way->upgrade google analytic module to google_analytics 6.x-3.x-dev(here is link  http://drupal.org/node/807234 )
2nd way->disabled "Track outbound links" in google analytic module(In Site configuration -> google analytic)
3rd way ->Add this patch to the "googleanalytics.js" file
// Track all external links as page views after URL cleanup.
             // Currently required, if click should be tracked as goal.
             _gaq.push(["_trackPageview", '/outbound/' + this.href.replace(/^(https?|ftp|news|nntp|telnet|irc|ssh|sftp|webcal):\/\//i, '').split('/').join('--')]);
+            if(this.target == '_blank'){
+                return true;
+            }
+            else{
             setTimeout('document.location = "' + this.href + '"', 100);
           }
+          }
           else {
             // External link clicked.
             _gaq.push(["_trackEvent", "Outbound links", "Click", this.href]);
@@ -51,10 +56,15 @@
             // that a user can click on the outbound link before the tracking code loads,
             // in which case the event will not be recorded.
             // See http://www.google.com/support/analytics/bin/answer.py?hl=en&answer=55527
+            if(this.target == '_blank'){
+                return true;
+            }
+            else{
             setTimeout('document.location = "' + this.href + '"', 100);
           }
         }
       }
+      }
     });
   });
 });
 
MORE REFERENCE VISIT BELOW LINK
        http://drupal.org/node/1057688

 

No comments:

Post a Comment