Javascript 使用javascript自动打开页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9029881/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
open page automatically using javascript
提问by rudolph9
Essentially, all I want to do is open an external web page after the current page is loaded via java script.
本质上,我想要做的就是在通过 java 脚本加载当前页面后打开一个外部网页。
open my page -> javascript tells browser to open external page -> external page being loaded into the broser
open my page -> javascript tells browser to open external page -> external page being loaded into the broser
How may I accomplish this?
我怎样才能做到这一点?
回答by mack
you may use this
你可以用这个
<html>
<head>
<script type="text/javascript">
function load()
{
window.location.href = "http://externalpage.com";
}
</script>
</head>
<body onload="load()">
<h1>Hello World!</h1>
</body>
</html>
回答by Quentin
Technically you can:
从技术上讲,您可以:
location.href = "http://example.net/";
… but you should perform an HTTP redirect instead as that is more reliable, faster and better food for search engines.
……但您应该改为执行 HTTP 重定向,因为这对搜索引擎来说更可靠、更快、更好。
回答by Sameera Thilakasiri
<html>
<head>
<script type="text/javascript">
function load()
{
window.location.href = "http://externalpage.com";
}
</script>
</head>
<body onload="load()">
<h1>Hello World!</h1>
</body>
</html>
Hope it should be window.location. Check the code.
希望它应该是window.location。检查代码。
回答by IsabelRuizN
You can also use the "open" method to open the source file or url on a new window.
您还可以使用“打开”方法在新窗口中打开源文件或 url。
window.open("anyfile.*");
or
或者
window.open("http://anylocation.com");
回答by Jason D'Souza
<body>
<script>
document.body.innerHTML += '<a href="https://www.google.com/" style="display: none;" id="link">Link</a>';
document.getElementById("link").click();
</script>
<body>
回答by venkata krishna
Hi please try this code for page loading time we will redirect whatever u configured the urls.
嗨,请尝试使用此代码进行页面加载,我们将重定向您配置的 url。
<!DOCTYPE html>
<html>
<head>
<script>
function myFunction() {
window.open('https://google.com');
}
</script>
</head>
<body onload="myFunction()">
</body>
</html>