Это все еще не кажется прямым.
http://www.w3.org/TR/MathML2/chapter8.html
Поддержка объектной модели документа MathML может быть запрошена путем вызова метода DOMImplementation :: hasFeature со строкой теста "org.w3c.dom.mathml"
Это подразумевает простой тест, однако Chrome и IE поддерживают его через плагины, но Chrome возвращает true , даже если у него нет плагина
Мое решение состоит в том, чтобы использовать спецификацию w3c, но это подходит для случаев, когда браузер [chrome] имеет противоположный ответ. Тогда я могу использовать MathJax при необходимости, который всегда, кроме Firefox. Скрипт идет в html разделе
<script type="text/javascript">
//Browser detector for Chrome
//returns true if the Browser is Chrome
function isChrome(){
var regex = /Chrome\/[0-9]{1,2}\.[0-9]/
var matches = navigator.userAgent.match(regex)
//console.log( matches )
return (matches!=null && matches.length==1)
}
/*
* Feature Detect for MathML as w3c specification
* <returns>boolean: true if mathML is supported in browser
*/
function hasFeatureMathML(){
MATHML_FEATURE = "org.w3c.dom.mathml" //as per w3c specification
MATHML_FEATURE_VERSION = "2.0" //Any version number appears to work
if(isChrome()) return false //Opps Chrome not natively supported yet
return document.implementation.hasFeature(MATHML_FEATURE, MATHML_FEATURE_VERSION )
}
/*
* init MathML use MathJax according to
* http://docs.mathjax.org/en/latest/dynamic.html
* with additional test to confirm necessity
* <returns>boolean: true if mathML is supported in browser
*/
function initMathML(){
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
//doctorBob added test on next line, return if has native support for MathML
if( hasFeatureMathML() ) return true
document.getElementsByTagName("head")[0].appendChild(script)
return false
}
//initialize in html <head> incase MathJax is required
var browserHasMathML = initMathML()
if( !browserHasMathML )console.log("No Native MathML using MathJax")
</script>
Я не особо задумывался об установке плагинов для браузера, потому что не у всех они установлены.
Это работает в IE 8, Chrome 39, Firefox 38, Komodo Edit 6