简体   繁体   English

将外部网页显示为网页

[英]Display external webpage into a webpage

I have 2 HTML files (both in the same directory). 我有2个HTML文件(都在同一目录中)。 How can I display content of one into another? 如何将一个内容显示为另一个?

I can think of these ways: 我可以想到以下方式:

  1. Create XMLHTTPRequest . 创建XMLHTTPRequest Fetch the HTML file and display in appropriate location. 提取HTML文件并显示在适当的位置。
  2. Use iframes 使用iframes

What are others methods to diplay external HTML file? 显示外部HTML文件还有哪些其他方法?

You can also use server-side proxy. 您也可以使用服务器端代理。 However, I'd personally use these iframes 但是,我会亲自使用这些iframe

If your host supports PHP then you can make the containing HTML file into a PHP file and include the other one with include() . 如果您的主机支持PHP,则可以将包含HTML的文件转换为PHP文件,并使用include()包含另一个HTML文件。 This is exactly the reason I learned PHP in the first place. 这正是我首先学习PHP的原因。

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 . 仅使用HTML ,您需要使用iframe来实现。 Your user will need to make 2 http requests to load 2 html files. 您的用户将需要发出2个http请求才能加载2个html文件。
  • Using only HTML and JavaScript , you also can work with XMLHTTPRequest or some JavaScript framework (like jQuery) to do that Ajax to you. 仅使用HTML和JavaScript ,您还可以使用XMLHTTPRequest或某些JavaScript框架(如jQuery)为您完成该Ajax。 Your users will need to make 2 http requests also, but SEO will be a problem in this case. 您的用户也需要发出2个http请求,但是在这种情况下,SEO会成为问题。

The third option, like others have suggested, is: 像其他建议一样,第三个选项是:

  • Using a server side processing , like the suggested PHP include or ASP.NET UserControl . 使用服务器端处理 ,例如建议的PHP includeASP.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. 我认为这是最好的方法,因为用户永远不会知道您有2个文件来显示该页面,并且只需要1个http请求。 And better for SEO crawlers too. 而且对于SEO爬虫也更好。

As an ASP.NET programmer, I personally like to have a base aspx page and split its sections using the UserControls ascx . 作为一个ASP.NET程序员,我个人希望拥有一个基本的aspx页面,并使用UserControls ascx拆分其各个部分。 The generated html remain clean in a single file. 生成的html在单个文件中保持干净。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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