问题
Can anyone tell me how to force Opera opera to render SVG in html?
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="142" height="142">
<rect x="19" y="19" width="104" height="104" r="0" rx="0" ry="0" fill="none" stroke="#000000"
style="stroke-opacity: 1; stroke-width: 2;" stroke-opacity="1" stroke-width="2"/>
<rect x="36" y="36" width="70" height="70" r="0" rx="0" ry="0" fill="none" stroke="#000000"
style="stroke-opacity: 1; stroke-width: 2;" stroke-opacity="1" stroke-width="2"/>
</svg>
This code works fine if file extension is not .html
upd: I'm trying to put div with svg inside generated by raphael.js in new window. And it doesnt work in Opera.
回答1:
To have SVG in HTML working, the browser must have an HTML5 parser and Opera will have one only since version 12.
If you absolutely have to have SVG right in the HTML code, you need your document to have an xhtml file extension an be a valid xml file (if you are running it from disc), and it also has to be served with application/xhtml+xml
mime type or another valid xml mime type when sent from a web server.
回答2:
Instead of SVG in HTML use SVG in XHTML.
(Be sure your web server is sending the correct mime type for XHTML.)
回答3:
Btw, we've recently released Opera 12 Alpha, which has an HTML5 Parser, and supports inline SVG. It should work in there, and subsequent later versions.
来源:https://stackoverflow.com/questions/7830158/whats-the-correct-way-to-use-svg-in-opera