Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading another html page from javascript

Is it possible to load a Javascript program from an html page and then make the Javascript load another html page instead of the page the loaded the program?

like image 859
Pranav Avatar asked Jan 07 '10 06:01

Pranav


People also ask

How do I move one HTML page to another using JavaScript?

Answer: Use the JavaScript window. location Property If you want to redirect the user from one page to another automatically, you can use the syntax window. location. replace("page_url") .

How do I load an HTML page in a div using JavaScript?

To load external HTML into a <div>, wrap your code inside the load() function. To load a page in div in jQuery, use the load() method.


3 Answers

Yes. In the javascript code:

window.location.href = "http://new.website.com/that/you/want_to_go_to.html";
like image 122
Grant Paul Avatar answered Oct 02 '22 18:10

Grant Paul


You can include a .js file which has the script to set the

window.location.href = url;

Where url would be the url you wish to load.

like image 24
Ravi Vanapalli Avatar answered Oct 02 '22 18:10

Ravi Vanapalli


Is it possible (work only online and load only your page or file): https://w3schools.com/xml/xml_http.asp Try my code:

function load_page(){
qr=new XMLHttpRequest();
qr.open('get','YOUR_file_or_page.htm');
qr.send();
qr.onload=function(){YOUR_div_id.innerHTML=qr.responseText}
};load_page();

qr.onreadystatechange instead qr.onload also use.

like image 24
Alexander V. Ulyanov Avatar answered Oct 02 '22 20:10

Alexander V. Ulyanov