简体   繁体   中英

How load HTML Pages, using button in javascript

I want to make button to load a html page using javascript. (Like Ajax Codes I don't want the page redirection).... but the code can't load html page & i want it to fill the page view.

so here is the code:

<!DOCTYPE html>
<html>
<body>

<h1>My First JavaScript</h1>

<button type="button"
onclick="document.getElementById("demo").innerHTML='<object type="type/html" data="register.html" >
submit</button>
<p id="demo"></p>

</body>
</html>

You have to escape the double quotes. Example:

<button type="button"
   onclick=" document.getElementById(\"demo\").innerHTML=
      '<object type=\"type/html\" data=\"http://www.target.com/register.html\">' ">
submit</button>

try like this:

    <!DOCTYPE html>
    <html>
    <style>
      #demo{
      width:700px !important;
      height:600px !important;

      }


  </style>
    <script>

    function loadPage(){
        document.getElementById("demo").innerHTML="<object type='type/html' data='register.html' >";

    }


      </script>
    <body>

    <h1>My First JavaScript</h1>

    <button type="button"
    onclick="loadPage();" >
    submit</button>
    <p id="demo"></p>

    </body>
    </html>

note: here register.html and this file should be in same folder or give relative path.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM