2

i have one submit button in my page , where i wanted to open that link in different window .

check this code

  <input class="btn add-to-cart-btn" onclick="one();two();" type="submit" value="More Info At {{ product.vendor }}"/>

java script code

<script>
  function one(){
   trackOutboundLink('{{ product.metafields.google.custom_label_0 }}');


}

function two(){
    window.open('{{ product.metafields.google.custom_label_0 }}');

}


  var trackOutboundLink = function(url) {
    ga('send', 'event', 'outgoing', 'click', url, {
    'transport': 'beacon',
    'hitCallback': function(){document.location = url;}
  });
    }
</script>

the "product.metafields.google.custom_label_0" is a static url .

if i click that submit page then that link is opening in new window as well as same window .

But i wanted to open in different window only . how to control this ?

Trend Snaps
  • 198
  • 4
  • 15

4 Answers4

1

The actual problem lies here:-

'hitCallback': function(){document.location = url;}

What happen that on button click first one(); and then two(); function called. So after opening the new window again, the original URL reloaded by the above code of function trackOutboundLink() which is called in function one();

So simple remove it or comment it like below:-

<input class="btn add-to-cart-btn" onclick="one();two();" type="submit" value="More Info At {{ product.vendor }}"/>

<script>
  function one(){
   trackOutboundLink('{{ product.metafields.google.custom_label_0 }}');
}

function two(){
    window.open('{{ product.metafields.google.custom_label_0 }}');
}

var trackOutboundLink = function(url) {
    ga('send', 'event', 'outgoing', 'click', url, {
    'transport': 'beacon',
    /* 'hitCallback': function(){document.location = url;} */
  });
}
</script>
Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
0

From : http://www.w3schools.com/jsref/met_win_open.asp

You can try : var myWindow = window.open("", "", "width=200,height=100"); for open an about:blank page in a new window.

You have to set windows size.

Clément Andraud
  • 9,103
  • 25
  • 80
  • 158
  • 1
    i am trying to prevent opening link in same window . check this out trendsnaps.com/products/a-initial-necklace – Trend Snaps Apr 29 '16 at 11:54
0

Change input type from "submit" to "button"

Karthikeyan
  • 347
  • 3
  • 8
0

Syntax

window.open(URL,name,specs,replace)

Try this

window.open("product.metafields.google.custom_label_0 ", "_blank");

more Info

shas
  • 703
  • 2
  • 8
  • 31