如何访问“嵌入”的内容标记为HTML [英] How to access the content of the "embed" tag in HTML

查看:84
本文介绍了如何访问“嵌入”的内容标记为HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个SVG文件,我不想将它粘贴到HTML文件中,因为它很麻烦。
因此,在咨询w3schools之后,嵌入标记似乎是将外部SVG文件包含到HTML中最安全的方式。

 < embed src =path_to_svgtype =image / svg + xmlid ='svgsource'/> 

但是,我需要通过DOM在主html文件中通过javascript访问svg元素。不幸的是,既不是

$ pre $ document $ get $ element $ p>

也不是

  document.getElementById('svgsource')。contentDocument 

适用于任何浏览器。使用对象标签也无法解决问题。

解决方案

完成转身!



原来你可以看到这个链接: http://xn--dahlstrm-t4a.net/svg/html/get-embedded-svg-document-script.html

(另外,去投票一些 ErikDahlström的其他答案给他一些积分给我劫持他的答案!)


I have an SVG file, and I don't want to paste it inside the HTML file because, well, it gets messy. So after consulting with w3schools, "embed" tag seemed the safest way to include an external SVG file into HTML.

<embed src="path_to_svg" type="image/svg+xml" id='svgsource' />

However, I need to access the svg elements through DOM via javascript in the main html file. Unfortunately neither

document.getElementById('my_svg_id')

nor

document.getElementById('svgsource').contentDocument

works in any browser. Using "object" tag doesn't do the trick either.

解决方案

Complete about turn!

Turns out you can, see this link: http://xn--dahlstrm-t4a.net/svg/html/get-embedded-svg-document-script.html

(Also, go and up vote some of Erik Dahlström's other answers to give him some points for me hijacking his answer!)

这篇关于如何访问“嵌入”的内容标记为HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆