草庐IT

HTMLObjectElement

全部标签

javascript - 为什么使用 HTMLObjectElement 动态生成 SVG 会导致跨源错误?

考虑以下JavaScript片段:constapp=document.getElementById('root');constsvg=`{console.log(obj.contentDocument.querySelector('svg'));},1500);(有关完整示例,请参阅thisJSFiddle)运行时,控制台(GoogleChrome)中会出现以下错误:UncaughtDOMException:Failedtoreadthe'contentDocument'propertyfrom'HTMLObjectElement':Blockedaframewithorigin"ht

javascript - 为什么使用 HTMLObjectElement 动态生成 SVG 会导致跨源错误?

考虑以下JavaScript片段:constapp=document.getElementById('root');constsvg=`{console.log(obj.contentDocument.querySelector('svg'));},1500);(有关完整示例,请参阅thisJSFiddle)运行时,控制台(GoogleChrome)中会出现以下错误:UncaughtDOMException:Failedtoreadthe'contentDocument'propertyfrom'HTMLObjectElement':Blockedaframewithorigin"ht