简体   繁体   中英

Display external webpage into a webpage

I have 2 HTML files (both in the same directory). How can I display content of one into another?

I can think of these ways:

  1. Create XMLHTTPRequest . Fetch the HTML file and display in appropriate location.
  2. Use iframes

What are others methods to diplay external HTML file?

You can also use server-side proxy. However, I'd personally use these iframes

If your host supports PHP then you can make the containing HTML file into a PHP file and include the other one with include() . This is exactly the reason I learned PHP in the first place.

You basically have three options to do this.

How do you even have proposed two:

  • Using only HTML , you need to do it with iframe . Your user will need to make 2 http requests to load 2 html files.
  • Using only HTML and JavaScript , you also can work with XMLHTTPRequest or some JavaScript framework (like jQuery) to do that Ajax to you. Your users will need to make 2 http requests also, but SEO will be a problem in this case.

The third option, like others have suggested, is:

  • Using a server side processing , like the suggested PHP include or ASP.NET UserControl . I think it's the best approach since the user will never know you have 2 files to show that page and also will need only 1 http request. And better for SEO crawlers too.

As an ASP.NET programmer, I personally like to have a base aspx page and split its sections using the UserControls ascx . The generated html remain clean in a single file.

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