[英]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.