Summary:
1. Need to open a new window to display a survey from a third party.
2. Cannot use JavaScript to open the window (currently using target="_blank".
3. Must use JavaScript to track clicks (currently using onclick).
4. original window must NOT change its content upon clicking.
I have a JSP that is trying to launch a third party survey in a new window. Originally, the code was launching the new window like this:
<a id="customer_survey_button" href="#" target="_blank" onclick="recordOutboundLink(this, 'Outbound Links', 'blah.com');openChildWindow('http://www.blah.com/f.asp?etcetera','TAKE SURVEY');return false;" class="genbut">TAKE SURVEY</a>
It worked in FF, but not Chrome. It caused a security problem with Chrome. Something like an 'unsafe JavaScript attempt to access a frame (new window) which loads one domain, while it’s origin is another domain. My solution was to open the window using HTML, like this:
<a id="customer_survey_button" href="http://www.blah.com/f.asp?etcetera" target="_blank" onclick="recordOutboundLink(this, 'Outbound Links', 'blah.com');return false;" class="genbut">Take Survey</a>
The problem is, that is not opening in a new window. During debugging, I removed the onclick from the above code, and it does open in a new window. I'm not sure if it is something wrong in the JS code...
<script type="text/javascript">
<!--
var pageTracker = _gat._getTracker("<%=googleTrackerId%>");
pageTracker._initData();
pageTracker._trackPageview();
function recordOutboundLink(link, category, action) {
try {
pageTracker._trackEvent(category, action);
setTimeout('document.location = "' + link.href + '"', 100)
}catch(err){}
}
// -->
</script>
...or if it is just a matter of using target and onclick in the same anchor tag. Any thoughts?
I researched elsewhere, and on Stack Overflow, I found the below results, but none seemed to address this situation. For example(s):
This helped in one way, because I was able to test the removal of the "return false". That had the same result as it did for "user1223427"- it rendered the same page in two different windows. It did not help because I need a non-JavaScript way to open the target URL (due to the security issues mentioned). OnClick for google analytics and target _blank. The link does not work?
This one doesn't help, because I'm not using JQuery and I don't understand the connection between the JQuery solution and my situation select onclick that contains _blank
This only applies to getting tracking code to work, not issues with a new window opening: Google Analytics - Download clicks tracking
I thought this one was going to have a good result, but it's solution is a JS one. Bug in external link tracking when opening the link in a new window in Google Analytics?