dom - javascript code doesnt work in browser -
i have code , using pspad editor when programing. when run "html page preview" in pspad works when try open in browser does't work. on chrome alerts "undefined not function". on firefox prints undefined , alerts empty window. on internet explorer nothing. can give me simple answer code example if possible?(this code should print content of xml)
<!doctype html> <html> <head> <script src="loadxmldoc.js"></script> <script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script> </head> <body> <script> var xmldoc= loadxmldoc('skoly.xml'); var d = document.createelement('div'); var t = document.createtextnode(xmldoc.xml); d.appendchild(t); document.write('<pre>' + d.innerhtml + '</pre>'); alert(xmldoc.xml); </script> </body> </html>
loadxmldoc.js:
function loadxmldoc(dname) { try { //internet explorer xmldoc=new activexobject("microsoft.xmldom"); } catch(e) { try { //firefox, mozilla, opera, etc. xmldoc=document.implementation.createdocument("","",null); } catch(e) { alert(e.message) } } try { xmldoc.async=false; xmldoc.load(dname); return(xmldoc); } catch(e) { alert(e.message) } return(null); }
this part returning error:
alert(xmldoc.xml);
i'm not sure trying achieve code trying return property "xml" of variable "xmldoc". in other words, work if xmldoc object looks this:
var xmldoc = { xml: "something here" };
it returning "cannot read property 'xml' of null" because xmldoc has value null , trying return property.
Comments
Post a Comment