Search code examples
iframesandbox

Detect support for srcdoc in iFrames


Does anyone know how to detect if the srcdoc attribute of iFrame is supported by the browser without relaying on version checks, etc?


Solution

  • This should do the trick in JavaScript executed in a browser:

    !!("srcdoc" in document.createElement("iframe"))
    

    Source https://github.com/jugglinmike/srcdoc-polyfill/blob/master/srcdoc-polyfill.js#L19