プロが教えるわが家の防犯対策術!

chromeだとエラーで表示できません。
どうすればいいのでしょうか?

window.onload=function(){
Docm = new ActiveXObject('microsoft.XMLDOM');
Docm.async = false;
Docm.load('xmlsrc');

var string = "";
if(Docm.documentElement.hasChildNodes())
{
var i = 0;
var n_num = Docm.documentElement.childNodes.length;
while (i < n_num)
{
string += Docm.documentElement.childNodes.item(i).text += " ";
i++;
}
}
else
{
string +="子ノードはありません。";
}
hyouji.innerHTML = string;
}

A 回答 (1件)

ActiveXObject('microsoft.XMLDOM')はIE以外は使えません。


読み込むXMLの構造が解らないので、正確な解答は出来ませんが、
汎用的にするなら、
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitio …
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<title>Test</title>
<script type="text/javascript">
//<![CDATA[
window.onload=function(){
var hyouji = document.getElementById("hyouji");
Docm = (window.ActiveXObject)?new ActiveXObject('microsoft.XMLDOM'):document.implementation.createDocument("", "", null);
Docm.async = false;
Docm.load('xmlsrc');
var string = "";
if(Docm.documentElement.hasChildNodes()){
var i = 0;
var n_num = Docm.documentElement.childNodes.length;
while (i < n_num){
if(Docm.documentElement.childNodes[i].nodeType==1){
string += Docm.documentElement.childNodes[i].childNodes[0].nodeValue;
string +=" ";
}
i++;
}
}else{
string +="子ノードはありません。";
}
hyouji.innerHTML = string;
}
//]]>
</script>
<body>
<div id="hyouji">
</div>
</body>
</html>
といったところでしょうか...
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!