Loading another html page from javascript

后端 未结 4 1710
南旧
南旧 2021-02-07 00:51

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?

4条回答
  •  北恋
    北恋 (楼主)
    2021-02-07 01:36

    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.

提交回复
热议问题