www.webdeveloper.com
Results 1 to 3 of 3

Thread: IS there any way to avoid ActiveXObject in javascript for reading documents ?

  1. #1
    Join Date
    Oct 2013
    Posts
    1

    IS there any way to avoid ActiveXObject in javascript for reading documents ?

    In need of desperate guidance

    1. Is there any way to avoid ActivexObject in JavaScript for reading documents and constructing xmls?

    2. Actual there is a problem with the client, he doesn’t like the IE security settings like "Access data source across domains" under Miscellaneous and "Run ActiveX controls and plug-ins".

    And It should support IE 7, 8 and above. If possible that should work in cross browser also.

    Currently in JavaScript, we are using the below codes:

    var xmlDoc = new ActiveXObject("MSXML2.DOMDocument"); -->for xml construction.

    var stm = new ActiveXObject("ADODB.Stream"); --> for reading the doc and docx file from client temporary path.

    What is needed:

    1. We need to find an alternate in order to avoid using the ActiveXobject.

    OR

    2. We need to automate the Internet Security Settings in client machine.

    Could some one help me in this please?

    Thanks
    Nanda

  2. #2
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,498
    You could have the documents uploaded to the server, have the server parse the file to get the data out, when the client has finished with that file, delete it off the server.

    This all depends on what your objectives are with accessing the data in this way.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  3. #3
    Join Date
    Feb 2003
    Location
    Michigan, USA
    Posts
    5,774
    You could try out Dean Edward's solution: http://dean.edwards.name/weblog/2006/04/easy-xml/

    Basically you create a new element with the tag name set to "xml". Then set the "src" property to the URL of an XML file.

    Another way would be to load the XML document in an IFRAME from a URL in the same domain as the current Web page. As long as the XML document in the IFRAME is in the same domain name as the parent page, JavaScript can access the window and document objects inside the IFRAME, and therefore JavaScript can extract those values.

    Perhaps something like this?

    Code:
    function loadXML(url, callback, context) {
        var iframe = document.createElement("iframe");
        iframe.onload = function() {
            callback.call(context, iframe.contentDocument);
            iframe.onload = null;
            document.body.removeChild(iframe);
            iframe = callback = context = null;
        };
    
        document.body.appendChild(iframe);
    
        iframe.src = url;
    }
    You would use it like this:

    HTML Code:
    <script type="text/javascript">
    
        // Procedural or Functional code:
        loadXML("/data.xml", function(doc) {
            $(doc).find("foo").each(function() {
                // do stuff
            });
        });
    
        // Object oriented code:
        var someObject = {
            foo: function() {
                loadXML("/data.xml", function(doc) {
                    this.extractData(doc);
                }, this); // Notice the third argument: "this" sets the value of "this" in the callback
            },
    
            extractData: function(doc) {
                $(doc).find("foo").each(function() {
                    // do stuff
                });
            }
        };
    
    </script>
    Note: This is untested code

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