2012-01-27 66 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> 
相關問題