While loading some HTML content in an iframe using the srcdoc
attribute, I encountered an issue where following anchor tag links inside the iframe caused the entire page to load within the iframe instead of scrolling to the linked id.
You can see a demonstration of this problem in this JSFiddle: https://jsfiddle.net/kzLdqjgs/5/
I managed to get the anchor tags working by using
src="data:text/html,<p>my html</p>"
, but I am curious as to why it did not work with srcdoc. Additionally, it is worth noting that the src attribute has a character limit of 32,768 for some implementations, and the content I wanted to load was over 60k characters long (although it seems to work fine in Chrome).