2012-01-27 65 views
5

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

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

我怎么可能做到这一点?

回答

13

你可以使用这个

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

从技术上讲,您可以:

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

...但你应该执行HTTP重定向,而不是因为这是更可靠的,对于搜索引擎更快,更好的食物。

2
<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的。检查代码。

0

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

window.open("anyfile.*"); 

window.open("http://anylocation.com"); 
-1

你好,请尝试页面加载时间,我们会重定向任何ü配置的网址,该代码。

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

 
<body onload="myFunction()"> 
 
</body> 
 

 
</html>

1
<body> 
<script> 
document.body.innerHTML += '<a href="https://www.google.com/" style="display: none;" id="link">Link</a>'; 
document.getElementById("link").click(); 
</script> 
<body> 
相关问题