繁体   English   中英

使用javascript自动打开页面

[英]open page automatically using javascript

本质上,我想要做的就是在通过 java 脚本加载当前页面后打开一个外部网页。

open my page -> javascript tells browser to open external page -> external page being loaded into the broser

我怎样才能做到这一点?

你可以用这个

<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> 

从技术上讲,您可以:

location.href = "http://example.net/";

……但您应该改为执行 HTTP 重定向,因为这对搜索引擎来说更可靠、更快、更好。

<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> 

希望它应该是window.location。 检查代码。

您还可以使用“打开”方法在新窗口中打开源文件或 url。

window.open("anyfile.*");

或者

window.open("http://anylocation.com");
<body>
<script>
document.body.innerHTML += '<a href="https://www.google.com/" style="display: none;" id="link">Link</a>';
document.getElementById("link").click();
</script>
<body>

嗨,请尝试使用此代码进行页面加载,我们将重定向您配置的 url。

 <!DOCTYPE html> <html> <head> <script> function myFunction() { window.open('https://google.com'); } </script> </head> <body onload="myFunction()"> </body> </html>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM