javascript:window.open(window.clickTag) opens double tabs in Firefox

Tweeden picture Tweeden · Mar 22, 2017 · Viewed 11.4k times · Source

I am using clickTags in my code for tracking. This is my setup.

<script type="text/javascript">
    var clickTag = "https://www.example.com";
</script>

<a href="javascript:window.open(window.clickTag)">
---Content---
</a>

The issue is with Firefox opening double tabs when I click on the link. I only want it to open to the information that is associated with the link. My question, is there a workaround or is there a bug with Firefox?

Answer

Edward Newsome picture Edward Newsome · Mar 22, 2017

For this i would create a function (see below)

<script type="text/javascript">
    function clickTag() {
    return "http://example.com"
    }
</script>

<a href="#" onclick="window.open(clickTag()); return false;">Link</a>

https://jsfiddle.net/3kdcyrbe/