[英]How to open multiple pop-up windows?
我有五個鏈接,每個鏈接都指向一個頁面。
function TohokuImgPopup(url) {
popupWindow = window.open(
url, 'popUpWindow'+randomno, 'height=246,width=228,left=0,top=0,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=no')
}
這是我正在使用的功能。 我對 5 個鏈接有不同的功能,每個鏈接都會打開一個新窗口。 但我一次只能打開一個彈出窗口。 如何打開多個彈出窗口?
我找到了答案。
<script type="text/javascript">
$(document).ready(
function a1(url) {
popupWindow1 = window.open(
url, 'popUpWindow1', 'height=250,width=234,left=0,top=0,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=no')
}
function a2(url) {
popupWindow2 = window.open(
url, 'popUpWindow2', 'height=250,width=234,left=0,top=0,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=no')
}
function a3(url) {
popupWindow3 = window.open(
url, 'popUpWindow3', 'height=308,width=299,left=0,top=0,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=no')
}
}
</script>
<a href="JavaScript:a1('images/focus_img1.html');">focus 1</a>
<a href="JavaScript:a2('images/focus_img2.html');">focus 2</a>
<a href="JavaScript:a3('images/focus_img3.html');">focus 3</a>
這些鏈接將在單獨的窗口中打開
我知道這個問題已經很久了,但我會回答,因為我在網上找不到任何可以明確回答問題的內容。 一種簡單的方法是使用帶有 click() 事件的鏈接。
$('body').on('click', 'a[data-popup]', function(e) {
var date = new Date();
var mSec = date.getTime();
my_window = window.open($(this).attr('href'), "Popup"+mSec, "top=0,left=0,menubar=no,toolbar=no,location=no, height=600, width=800");
e.preventDefault();
my_window.focus();
});
使用 date.getTime() (不可能重復任何返回值,因為它是自 1970 年 1 月 1 日以來的秒數...)使每個新彈出窗口都具有新名稱:)
以下代碼將根據需要打開彈出窗口的數量
<html>
<head>
<title></title>
<script type="text/javascript">
function TohokuImgPopup(url) {
window.open(url,"windowName","windowFeatures")
window.open(url,"DifferentWindowName","windowFeatures")// different name for each popup
// create windows as much as you want to create
}
</script>
</head>
<body>
<form>
<input type="button" value="Open Windows" onclick="TohokuImgPopup()">
</form>
</body>
您需要確保每個窗口名稱都不同,否則最后一個彈出窗口將覆蓋它之前的彈出窗口。 結果你會得到一個彈出窗口
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.