简体   繁体   中英

Load PHP page within HTML page with Javascript On Page Load

I am trying to figure out how to load a PHP page within an HTML page when the page loads with pure JavaScript. Nothing fancy. Just want to use the HTML page as a dummy.

Update 1:

After much confusion I wanted to update my issue.

I am trying to port my PHP website into a web app using Framework7. F7 is a an html and javascript only based system and doesn't play well with PHP. Not only that I am going to use phonegap to build the app, which also does not accept php.

Now I am trying to ask how I can use javascript/ajax to load a .php page within an .html page when the html page loads. Not when I button is clicked.

Basically I am using the .html files as dummy files just to load my php files within them.

If someone can suggest an easier way to approach this, I'm all ears.

也许您可以使用<iframe src="yourfile.php" name="targetframe" frameborder="0"> </iframe>然后修改CSS以显示它

If you want to get content after loading the page. Than you should send an AJAX request. Like (pure JavaScript): https://www.w3schools.com/xml/ajax_intro.asp

or with jQuery: http://api.jquery.com/jquery.ajax/

$.ajax({
  url: "test.html"
}).done(function(e) {
  $( '.your-div').html(e);
});

Than you could load your HTML / PHP or else in to your page, after page loading.

You could use javascript to append an iframe:

<script type='text/javascript'>
window.onload = function() 
{
    var iframe = document.createElement('iframe');
    iframe.style.display = "none";
    iframe.src = 'the url goes here';
    document.body.appendChild(iframe);
};
</script>

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