1

我试图通过单击一个按钮打开两个不同的窗口,但是当我单击该按钮时,它会打开同一个窗口两次。这是我的功能:

function flush(form) {
    var custid = form.custid.value;
    var url1 = "https://www.blabla.com?type=customer&id="+custid;
    flushWindow1 = window.open(url1);
    var url2 = "https://web.blabla.com?type=customer&id="+custid;
    flushWindow2 = window.open(url2);
}  

有谁知道我该怎么做?

4

3 回答 3

0

尝试为 window.open() 方法提供第二个参数,即窗口的名称,如果名称不同,则相同的 url 将在不同的窗口中打开。例如

function flush(form) {
    var custid = form.custid.value;
    var url1 = "https://www.blabla.com?type=customer&id="+custid;
    flushWindow1 = window.open(url1,"flushWindow1");
    var url2 = "https://web.blabla.com?type=customer&id="+custid;
    flushWindow2 = window.open(url2,"flushWindow2");   
}

演示

于 2012-10-08T10:27:34.007 回答
0

来自:JSfiddle 点击两个窗口

$('document').ready(function(){
    $('input').click(function(){
        window.open("https://www.google.com.pk/search?q=123&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a")
        window.open("https://www.google.com.pk/search?q=abc&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a")
    });
});  
于 2012-10-08T10:38:19.717 回答
0

尝试通过添加参数在新窗口/选项卡中打开'_blank'
,然后window.focus();在打开两个新窗口后通过放置在要聚焦的窗口后面来聚焦你想要的窗口

function flush(form) {
    var custid = form.custid.value;
    var url1 = "https://www.blabla.com?type=customer&id="+custid;
    flushWindow1 = window.open(url1, '_blank');
    var url2 = "https://web.blabla.com?type=customer&id="+custid;
    flushWindow2 = window.open(url2, '_blank');
    window.focus(); // focus on url2
}  
于 2012-10-08T10:42:22.180 回答