1. 程式人生 > >N 秒打開一個新窗口

N 秒打開一個新窗口

pub aid tar html http jquer open ide java

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>

<script type="text/javascript" src="jquery-1.9.1.min.js"></script>
</head>
<body>

<a id="article"
target="_blank"><span id="spanId">點擊</span>d</a>
<script>
$("#article").click(function() {
openNewWindow();
setTimer();
});

var n = 0;
function setTimer() {

n++;
$("#article").text("已點擊" + n + "次");
setTimeout(function() {
openNewWindow();
setTimer();
}, 2000)

}
function openNewWindow() {
//var a = $(‘a‘)[0];
let a = $("<a href=‘http://baijiahao.baidu.com/s?id=1588483985812614469&hidebar=1‘ target=‘_blank‘>baidu</a>").get(0);
let e = document.createEvent(‘MouseEvents‘);
e.initEvent( ‘click‘, true, true );
a.dispatchEvent(e);
}
</script>
</body>
</html>

N 秒打開一個新窗口