2011-02-15 33 views
6

javascript:如何檢測HTML img元素支持SVG?javascript:如何檢測HTML img元素支持SVG?

我嘗試這樣做,但它不工作:

x = new Image(); 
x.onload = function(){ 
    if (x.width) { 
    alert('svg in img tag supported!'); 
    } 
}; 
x.src = 'test.svg'; 
+0

重複的http://stackoverflow.com/問題/ 4118254 /可靠 - 檢測-img-tag-support-for-svg – jbeard4 2011-02-16 03:45:22

+1

它不是重複的,這裏我回答「img標籤中的svg」,而不是「inline svg in html5」 – Yaffle 2011-03-23 18:28:44

回答

-1

爲特徵檢測這樣使用modernizr

if (Modernizr.SVG){ 
    //svg supported 
} 
+0

這不會檢查img元素中的支持。 – Julian 2013-02-25 18:55:59