如何在另一个html页面中包含一个html页面(作为标题)?

时间:2013-09-27 09:44:07

标签: c# html asp.net css

我正在尝试包含一个html页面,该页面将成为我的主页面的标题。两个页面都部署到不同的服务器。我目前正在使用框架。标题目前有一些固定的宽度,我无法更改其宽度我需要它以适应我的主页面的屏幕。 是否可以使用框架或者我可以使用其他任何方法吗?

2 个答案:

答案 0 :(得分:1)

你可以使用php(如果你的服务器能够运行php文件)假设你的html文件被称为“header.html”和“content.html”,那么php文件可能看起来像这样:

<html>
<?php
$HEADER_URL = "www.testsiteheader.com/header.html";
Include($HEADER_URL);
Include("content.html");
?>
</html>

例如,这段代码:

<?php
Include("http://stackoverflow.com/questions/19047619/how-to-include-one-html-pageas-header-in-another-html-page");
?>

使网站看起来像这样: http://imgur.com/QB5MZu6

重要: 您可能需要在php-config文件中更改此内容:

allow_url_include = Off

allow_url_include = On

答案 1 :(得分:0)

您可以使用jQuery和Ajax来管理它:

以下函数将在document.ready事件上运行,如果代码错误{{1},则调用jQuery的Ajax函数以URL方式访问asynchronous集合执行函数并在页面上显示错误。如果成功,error函数将执行并将success控件的html内容设置为检索到的对象。

DivName

此代码依赖于以下事实:您有一个名为 $(document).ready(function() { $.ajax({ url: 'MyPage.aspx', //path to external file async: true, error:function(ajaxrequest){ $('#DivName').html('Error fetching content. Server Response: '+ajaxrequest.responseText); }, success:function(content){ $('#DivName').html(content); } }); }); 的外部网页,以及ID为MyPage.aspx的当前页面上的控件