How to include html text from another file into an HTML5 page

I have heard about objects, embeds, and even iframes for this purpose. In these options I had formatting issues with the main page style not being applied. Thus, I preferred jQuery and the <article> tag.

So to keep it simple, assign an ID to your article tag,


<article¬†id=”mycustomhtml”>

</article>

and load the page using jquery for the article mycustomhtml


<script>

$(“#mycustomhtml).load(“customhtml.txt”, function (response, status, xhr) {

if (status == “error”) {

var msg = “Error: “;

alert(msg + xhr.status + ” “ + xhr.statusText);

}

});

< /script>

This is as simple as it gets.

I would like to thank Shakeel Abdul Rehman for his help in this snippet.

About these ads

About irtazaali
Project Manager, Application Developer, and Technical Consultant in a wide variety of business applications. Particularly interested in project and product development using C#.NET, ASP.NET, XAML, Visual Basic with datastores like XML, SQL Server, Oracle, and MySQL. Always interested in migration projects and ventures in product development. Have 12 years experience in commercial software product development. Quite knowledgeable in ROI and infrastructure development operations. Have previously worked as project manager-software products at US and UK based companies providing business intelligence software solutions. Hold MCSD.NET, OCP, and OCA certifications.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 80 other followers

%d bloggers like this: