I’ve been reading with interest about the dialog element in HTML:
<dialog id="helpOnName">
<p>
The name is arbitrary. There is no validation, whatsoever.
</p>
</dialog>
So, that’s well for this simple text. However, with growing complexity, I’d rather have something like
<dialog url="helpOnName.html"></dialog>
In other words: Rather than embedding the dialog contents into the opening page, I’d like it to be read from another file.
Is that possible? How? (Using JQuery would be fine.)
2
Answers
You may have different options to achieve the goal to have content loaded from an external resource.
dynamically in the dialog
<iframe>
tag<object>
tagThis is the demo for the third and most original option of those.
The content for the
<dialog>
is specified by an<object>
element fed by an url having its content. As a fallback, I added the option that will override its content with a default template defined in the page itself.<object>: The External Object element
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/object
:scope (worth of mention)
*for selecting only starting from the direct children
https://developer.mozilla.org/en-US/docs/Web/CSS/:scope
This is an answer better covering
<iframe>
<embed>
<object>
Difference between iframe, embed and object elements
And I would add I forgot to mention
<link>
Here is another way of doing it with
fetch()
: