Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using <object> tag to include HTML content: allowed format of included file

Tags:

html

OK, I know how to include HTML content from a separate file using the <object> tag. What I can't find any info about is what is allowed/required within the included HTML file. Can said included file merely be some text with some HTML tags, or does it have to be a complete HTML file with headers, <head>, and <body>? How does this appear within the DOM of the original document, if it appears within that DOM at all? Or are the two documents treated entirely separately?

Yes, I know, I could experiment to see what works. However, I know enough about HTML to know that what happens to work, for now, may not be the correct way to do things. I am not expecting anyone to list out all the rules here, but if someone could post some links I would much appreciate it. This is a topic that has proven exceeding difficult to search the internet for.

like image 784
GrantRobertson Avatar asked Sep 27 '22 23:09

GrantRobertson


2 Answers

In 13.5 Notes on embedded documents, I believe I have found the answer to both of my questions. The second paragraph says,

An embedded document is entirely independent of the document in which it is embedded. For instance, relative URIs within the embedded document resolve according to the base URI of the embedded document, not that of the main document. An embedded document is only rendered within another document (e.g., in a subwindow); it remains otherwise independent.

So, yes, as both @Quentin and @Sinan said, it would require the embedded .html file to be a complete, valid .html file. And, no, it would not become part of the DOM of the original document.

Thanks to everyone for their prompt assistance. The StackOverflow community continues to amaze me.

like image 145
GrantRobertson Avatar answered Nov 15 '22 08:11

GrantRobertson


<object> is a way to include a generic media object.

An HTML document is an example of such.

The HTML spec doesn't describe a means to provide a fragment of HTML to a browser, only a complete document. There is no standard MIME type for a fragment of HTML.

Therefore: You should use complete HTML documents.

That said, if you are going down that route, you would almost certainly be better off using <iframe> which has a much more featureful and robust set of APIs and documentation surrounding it.

How does this appear within the DOM of the original document, if it appears within that DOM at all?

As an object element. The child nodes of which are whatever alternative content you provide between the start and end tag.

Or are the two documents treated entirely separately?

Yes, much like an iframe.

like image 24
Quentin Avatar answered Nov 15 '22 08:11

Quentin