我试图通过单击按钮打开两个不同的窗口,但是当我单击按钮时,它会打开两次相同的窗口。这是我的功能:
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);
}
有谁知道我该怎么做?
答案 0 :(得分:0)
尝试为window.open()方法提供第二个参数,这是窗口的名称,如果名称不同,则相同的url将在不同的窗口中打开。 e.g。
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");
}
答案 1 :(得分:0)
来自:JSfiddle Two windows on a Click
$('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")
});
});
答案 2 :(得分: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
}