www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 18

Thread: [RESOLVED] IE8 documentElement is null for local files

  1. #1
    Join Date
    May 2010
    Posts
    51

    resolved [RESOLVED] IE8 documentElement is null for local files

    My files are not hosted on a server using http. They come with many sound files to practice vocabulary. The problem is that IE8 does not give me the opportunity to load xml course info, I suspect it is because Microsoft might think IE is for network use only (funny they don't think that when MS Word is concerned). Everything works fine in opera and firefox but IE does not give me a documentElemet after loading the xml. Here is some code to reproduce:
    Code:
    <html>
    <head>
    <title>test course</title>
    </head>
    <body>
    	<textarea id="output" style="width:600px;height:300px"></textarea>
    <script>
    var xmlhttp=false;
    /* running locally on IE5.5, IE6, IE7 */ ; /*@cc_on
    if(location.protocol=="file:"){
    if(!xmlhttp)try{ xmlhttp=new ActiveXObject("MSXML2.XMLHTTP"); }catch(e){xmlhttp=false;}
    if(!xmlhttp)try{ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }catch(e){xmlhttp=false;}
    } ; @cc_off @*/
    /* IE7, Firefox, Safari, Opera... */
    if(!xmlhttp)try{ xmlhttp=new XMLHttpRequest(); }catch(e){xmlhttp=false;}
    /* IE6 */
    if(typeof ActiveXObject != "undefined"){
    if(!xmlhttp)try{ xmlhttp=new ActiveXObject("MSXML2.XMLHTTP"); }catch(e){xmlhttp=false;}
    if(!xmlhttp)try{ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }catch(e){xmlhttp=false;}
    }
    /* IceBrowser */
    if(!xmlhttp)try{ xmlhttp=createRequest(); }catch(e){xmlhttp=false;}
    var outp=document.getElementById("output");
    function processRequest(){
    	if (xmlhttp.readyState == 4) {
    		var bsIEdebuggerDoesntShowVarsInScope=xmlhttp;
    		var tmp=new Array();
    		var i=0;
    		tmp[i]="What is the responseText:::::::-";i++;
    		tmp[i]=xmlhttp.responseText;i++;
    		tmp[i]="-::::::::\n";i++;
    		tmp[i]="What is the responseXML.documentElement::::::-";i++;
    		tmp[i]=xmlhttp.responseXML.documentElement;i++;
    		tmp[i]="-::::::::\n";i++;
    		tmp[i]="Is the responseXML.documentElement null::::::-";i++;
    		tmp[i]=!xmlhttp.responseXML.documentElement;i++;
    		tmp[i]="-::::::::\n";i++;
    		tmp[i]="Is the responseXML.firstChild null::::::-";i++;
    		tmp[i]=!xmlhttp.responseXML.firstChild;i++;
    		tmp[i]="-::::::::\n";i++;
    		outp.value=tmp.join("");
    	}
    }
    xmlhttp.onreadystatechange=processRequest;
    xmlhttp.open("GET", "data.xml", true);
    xmlhttp.send(null);
    </script>
    </body>
    </html>
    The data.xml is utf-8 saved and I opened it in several browsers:
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <lesson>
    <info> some info</info>
    </lesson>
    output is:
    Code:
    What is the responseText:::::::-<?xml version="1.0" encoding="utf-8"?>
    <lesson>
    <info> some info</info>
    </lesson>
    -::::::::
    What is the responseXML.documentElement::::::--::::::::
    Is the responseXML.documentElement null::::::-true-::::::::
    Is the responseXML.firstChild null::::::-true-::::::::

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    IE blocks by default ActiveX and javascript when running local files. It will show you a small "banner" upside with a message: "To help protect your security IE has restricted this webpage from running scripts or ActiveX controls..." You must click that banner and chose to allow the code. You may bypass that by modifying the Security level in Options, but it is nor recommended, as it will open a security hole - IE is quite vulnerable

  3. #3
    Join Date
    May 2010
    Posts
    51
    Ok, I see the security risk in letting local files use xmlhttprequest or have an iframe (I tried that too) load the xml after which the containing window will read it.
    If a file is local you can open up any file from the disk and post it to some website, maybe even open one of windows help files and abuse active x controls on them to gain write permission to the system.

    What I don't understand is why I cannot find anything that will allow me to "trust" a local page. IE just disables it altogether and other browsers don't seem to be worried about security risks involved (but they might disable it in the future). It would be better if they would let the user set up some sort of trust for locally run files.

    Ah well, back to flex. I guess MS, Mac ad opera's bashing of it was not hindered by any knowledge of how quirky html(5) really is (the main success of flash in the first place)

  4. #4
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Quote Originally Posted by amsterdamharu View Post
    What I don't understand is why I cannot find anything that will allow me to "trust" a local page. IE just disables it altogether and other browsers don't seem to be worried about security risks involved (but they might disable it in the future).
    Probably because IE simply can not do that. Why? Ask Bill Gates

  5. #5
    Join Date
    May 2010
    Posts
    51
    Quote Originally Posted by Kor View Post
    IE blocks by default ActiveX and javascript when running local files. It will show you a small "banner" upside with a message: "To help protect your security IE has restricted this webpage from running scripts or ActiveX controls..." You must click that banner and chose to allow the code. You may bypass that by modifying the Security level in Options, but it is nor recommended, as it will open a security hole - IE is quite vulnerable
    Nope, not clicking on the banner would result in me staring at the empty textarea until something would happen, it never will because none of the script will be executed until you click the banner and allow it to.

    Thanks for your reply anyway, I guess this project will go in the bin until browser developers start seeing the benefit in running local files. My idea was to let the browser be my JVM, html be my swing and JavaScript be my JAVA. Program it one time and have it run on most every machine with a browser supporting the script (that would include many smart phones as well). But since this needs to run locally as an application (there are lots of external resources like sound and video) it will be impossible to do in html(5). I'll have a look at adobe air but it's not as widely supported as html/JavaScript.

  6. #6
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    The problem is that there is no browser entirely prepared for HTML 5 for the moment. It is not very sure that they will be in the near future (even HTML 5 was born in 2004)

    Chrome is probably more close to HTML 5 interpretation, but not even Chrome is able to run all the HTML 5 specifications. Nor CSS3 entirely.

    Why do you need that HTML 5?

  7. #7
    Join Date
    May 2010
    Posts
    51
    Why do you need that HTML 5?
    I have made a simple course in flash, it plays sound and shows texts then you can evaluate if it was correct or not. It uses general objects as question steps so it can be re-used to practice calculus, geography for kids or language study for adults. Its sort of a flashcard app but with video and sound (if supported by browser) and will have several question evaluation classes (like self evaluation "I was wrong/right", fill in number, date, text, multiple choice)

    Before spending more time programming more classes for the course app I want to check what platform would be best to release it on. HTML 5 seemed to me the best choice since it is available for mobile phones, windows, mac and linux. Java or flash are less desired options since it requires the user to install and configure extra software.

    Especially mobile phones would be nice since you can practice your vocab while commuting or waiting for something.

    Here come the trouble though, opera mobile not yet supports audio tag. It might support Audio object but doesn't play anything and it will not support the html5 local storage for local files. It doesn't even allow cookies from local files. So when audio will be supported saving state is still not possible. IE has been a disaster, where I have minimal functionality working in firefox and opera IE just does it's utter best not to make it work.

    But for all the small problems that the browsers will have, at least it is available with limited but soon to be expanded functionality where I am afraid with the recent bashing against flash that this might be less and less supported. Android will have/has a good html5 browser, I think iphone has good support, opera mobile can be used for windows phones (without sound or saving state) and firefox for any desk/laptop.
    Last edited by amsterdamharu; 05-19-2010 at 10:37 AM.

  8. #8
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Quote Originally Posted by amsterdamharu View Post
    HTML 5 seemed to me the best choice since it is available for mobile phones, windows, mac and linux.
    No. You confound the Operating Systems with the browsers. OS has nothing to do with HTML. The way HTML, CSS, and Javascript are interpreted is a privilege of the browser. On the same OS, say Windows, FireFox may interpret some HTML, CSS or JavaScript otherwise than IE8, and IE8 otherwise than IE7 or IE6, or Chrome, or Opera...

    Smartphones use different browsers as well. Some use a variant of Safari browser (iPhone), others various browsers based on WebKit engine (on Android or on the new Symbian equipped Nokia phones, for instance), and so on.

    None of them interpret HTML 5 indeed and entirely. So far.

  9. #9
    Join Date
    May 2010
    Posts
    51
    None of them interpret HTML 5 indeed and entirely. So far.
    Sound and video would be cool but showing images and text will do for now. I am sure that is what most browsers on most devices can do.

    I'm just hoping that most browsers will go in the (same)direction of html5 but whatever will happen for a simple flashcard app I think a browser that runs the script would be better than flash or java since every device/os has one.

    Minimal requirement is loading the xml with step data (like 1. show text, 2. wait, 3. show text (the answer).
    question data: (what text to show in step 1 and id of the element, how long to wait in step 2, what text to show in step 3 and id of the element.
    Question evaluation type: like self eval, number, date, text, multiple choice.
    This would separate the code from the data. Someone making a course only needs to design the html and create the xml. A text step will contain the id of the element to put the text in. A sound step would need the relative path and name of the file to (try to) play and so on.

    If we drop the sound and video for now I am sure you'd agree that using a browser to host the application would be best. Even with all the quirkiness it will be the most available one.

  10. #10
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Quote Originally Posted by amsterdamharu View Post

    If we drop the sound and video for now I am sure you'd agree that using a browser to host the application would be best. Even with all the quirkiness it will be the most available one.
    Agree. Except that I see no wiliness from browsers' vendors (especially IE) to implement HTML 5 and CSS3 in their products in the near future. Or if something is not accessible on about 60% of the market (IE), that something is not to be used yet. We must code for the majority, unfortunately, not for the top equipped users...

  11. #11
    Join Date
    May 2010
    Posts
    51
    Yes, I should implement IE as well but it will take a lot more time (it's just not as much fun as scripting in Firefox with firebug).

    I am doing this for fun, haven't programmed anything professionally for 3 years and now trying to make courses for Chinese that want to learn English. Will try to make vocabulary practice and reciting text stuff with self evaluating answer classes.

    My real concern is that other browsers might implement the no xmlhttprequest.documentElement and no access to iframe content for local files. It would break the the most importaint requerement of the application.

    Now thinking of supplying the course data through a js file. It would be more robust.

    This got me a bit frustrated since the IE debugger shows firstChild and stuff but cannot access it with script. No exception is thrown as well (a "not allowed from file:// protocol or something would be nice").

  12. #12
    Join Date
    Jan 2009
    Posts
    3,346
    The analogy was already made about emulating Java technologies....why not just create the application in Java (you can use embedded html engines and such for display if you want).

  13. #13
    Join Date
    May 2010
    Posts
    51
    why not just create the application in Java
    Not sure how widely supported java is. For me it's no trouble to install a jvm on a desk/lapt but mobile devices might be a different story.

    A Java program/midlet will not allow designers to change the look to whatever they want. In html all you need is some elements that support innerHTML (Nice and flexible and in my oppinion a good thing) to show the text. Some image elements to set src for.

    I am just hoping that html5 will get enough momentum for browser manufacturers to start implementing it. Even some parts of it like sound would already make a huge difference.

  14. #14
    Join Date
    Jan 2009
    Posts
    3,346
    Quote Originally Posted by amsterdamharu View Post
    Not sure how widely supported java is. For me it's no trouble to install a jvm on a desk/lapt but mobile devices might be a different story.

    A Java program/midlet will not allow designers to change the look to whatever they want. In html all you need is some elements that support innerHTML (Nice and flexible and in my oppinion a good thing) to show the text. Some image elements to set src for.

    I am just hoping that html5 will get enough momentum for browser manufacturers to start implementing it. Even some parts of it like sound would already make a huge difference.
    For that matter how many mobile devices parse javascript?

  15. #15
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Quote Originally Posted by criterion9 View Post
    For that matter how many mobile devices parse javascript?
    All. But there is the same situation as in the workstations world: different bugs or incomplete (or lack of) implementation. Not many, but enough to give you some head ache. See:
    http://www.quirksmode.org/mobile/browsers.html

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles