2010-01-07 159 views
18

是否可以从html页面加载Javascript程序,然后使Javascript加载另一个html页面而不是加载该程序的页面?从javascript加载另一个html页面

+2

你的“负载意味着什么”。你的意思是这样的:1)加载HTML页面2)用'

6

可以包括有脚本设置.js文件的

window.location.href = url; 

其中URL将要加载的URL。

2

是否有可能(的工作只在网上和负载只有你的页面):https://www.w3schools.com/xml/xml_http.asp试试我的代码:

function load_page(){ 
qr=new XMLHttpRequest(); 
qr.open('get','http://www.your_site.com/your_file.htm'); 
qr.send(); 
qr.onreadystatechange=function(){your_div.innerHTML=this.responseText} 
};load_page(); 
+0

这是问题的答案,而不是将重定向到另一个页面的href更改。相反,它会以字符串的形式获取所请求文件的原始源代码。 – Rafe 2017-11-25 10:01:28

0

您可以使用下面的代码:

<!DOCTYPE html> 
<html> 
    <body onLoad="triggerJS();"> 

    <script> 
     function triggerJS(){ 
     location.replace("http://www.google.com"); 
     /* 
     location.assign("New_WebSite_Url"); 
     //Use assign() instead of replace if you want to have the first page in the history (i.e if you want the user to be able to navigate back when New_WebSite_Url is loaded) 
     */ 
     } 
    </script> 

    </body> 
</html> 
相关问题