只需在页面加载期间更改窗口位置。
这里有一个
SSCCE
只需复制粘贴就行了。
<!doctype html>
<html lang="en">
<head>
<title>SO question 2222034</title>
<script>
window.onload = function() {
setTimeout(function() {
window.location = 'http://download.java.net/maven/1/jstl/jars/jstl-1.2.jar';
}, 2000); // It's "cool" to let user wait 2 more seconds :/
}
</script>
</head>
<body>
<p>The download of jstl-1.2.jar will start shortly...</p>
</body>
</html>
或者,如果您需要使用Post,只需提交一个隐藏表单:
<!doctype html>
<html lang="en">
<head>
<title>SO question 2222034</title>
<script>
window.onload = function() {
setTimeout(function() {
document.getElementById('downloadform').submit()
}, 2000); // It's "cool" to let user wait 2 more seconds :/
}
</script>
</head>
<body>
<p>The download of jstl-1.2.jar will start shortly...</p>
<form id="downloadform" action="http://download.java.net/maven/1/jstl/jars/jstl-1.2.jar"></form>
</body>
</html>