[英]How to open link in new tab and close it immediately after page load?
我在一個頁面上有兩個鏈接。 當我單擊第一個鏈接時,我希望該鏈接在新選項卡中打開並在頁面加載時立即關閉。 我希望第二個鏈接也發生同樣的情況。
另外,如何將這一步自動化“n”次?
您可以嘗試使用此功能:
function openUrl(url, title) {
if (!title) {
title = 'Just another window';
}
var x = window.open(url, title, 'toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,resizable=1');
x.blur();
x.close();
}
該函數接受兩個參數:URL(新窗口的 URL)和標題(將在新創建的窗口上顯示的標題)。
<html>
<head>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.min.js"></script>
</head>
<body>
<form action="http://google.ca" id='idForm'>
<div>
<button type='submit' >post</button>
</div>
</form>
</body>
<script>
$("#idForm").submit(function(e) {
var form = $(this);
var url = form.attr('action');
$.ajax({
type: "POST",
url: url,
data: form.serialize(), // serializes the form's elements.
success: function(data)
{
alert(data); // show response from the php script.
}
});
e.preventDefault(); // avoid to execute the actual submit of the form.
});
</script>
</html>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.