简体   繁体   English

在两个窗口中打开页面

[英]page opening in both window

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 java脚本代码

<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 . “product.metafields.google.custom_label_0”是一个静态网址。

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 ?如何控制这个?

The actual problem lies here:-真正的问题在于:-

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

What happen that on button click first one();在按钮上单击第one();会发生什么one(); and then two();然后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();所以再次打开新窗口后,原来的URL被上面在函数trackOutboundLink()中调用的函数trackOutboundLink()代码重新加载了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>

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

You can try : var myWindow = window.open("", "", "width=200,height=100");你可以试试: var myWindow = window.open("", "", "width=200,height=100"); for open an about:blank page in a new window.在新窗口中打开 about:blank 页面。

You have to set windows size.您必须设置窗口大小。

将输入类型从“提交”更改为“按钮”

Syntax句法

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

Try this尝试这个

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

more Info更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM