简体   繁体   English

如何在Chrome中通过window.open打开多个电子邮件客户端窗口?

[英]How to open multiple e-mail client windows by window.open in Chrome?

I have the following html/js code: 我有以下html / js代码:

<button onclick="openWindows()">Open 3 e-mail windows</button>
<script>
      function openWindows(){
          window.open("mailto:asd@gmail.com","_self",'PopUp1');
          window.open("mailto:asd2@gmail.com","_self",'PopUp2');
          window.open("mailto:asd3@gmail.com","_self",'PopUp3');
      } 
</script>

This code should open 3 different e-mail client windows. 此代码应打开3个不同的电子邮件客户端窗口。 In the IE and FF the code works correctly, but in Chrome only one (the last) window is displayed. 在IE和FF中,代码可以正常工作,但在Chrome中,仅显示一个(最后一个)窗口。 Is there any browser independent solution which allows to open multiple windows all at once? 是否有任何独立于浏览器的解决方案可以一次打开多个窗口?

Change the "_self" with "_blank" . "_blank"更改"_self" "_blank"

Beware - many browsers block popups by default. 当心-许多浏览器默认情况下会阻止弹出窗口。

I just ran into the same issue. 我只是遇到了同样的问题。 Changing it to _blank did not work for me (on chrome 43). 将其更改为_blank对我不起作用(在chrome 43上)。

Instead I added a setTimeout to the mailto calls and it worked as expected. 相反,我将setTimeout添加到mailto调用中,并且按预期方式工作。

Around 500ms between messages seems to work for me. 两次消息之间大约500毫秒的间隔似乎对我有用。

      setTimeout(function() {window.open("mailto:asd@gmail.com","_self",'PopUp1');}, 500);
      setTimeout(function() {window.open("mailto:asd2@gmail.com","_self",'PopUp2');}, 1000);
      setTimeout(function() {window.open("mailto:asd3@gmail.com","_self",'PopUp3');}, 1500);

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

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