Click here to Skip to main content
16,018,802 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I am using this code fragment
JavaScript
var fso = new ActiveXObject("Scripting.FileSystemObject");
var s = fso.OpenTextFile(dir + "modules.txt", 2, true, -2);
s.WriteLine(tobewritten);
s.Close();
fso = s = null;
//alert (s);
if (s = "null")
    alert("Records updated");
window.location.href = 'main.html';

This is working fine with IE. But I need a solution to get it worked in Firefox. What should I do
Posted
v2

1 solution

Go through the Blog - Cross browser XMLHttpRequest[^]
Quote:
JavaScript
try {
    // test to see if XMLHttpRequest is defined
    XMLHttpRequest.DONE;
}
catch (e) {
    XMLHttpRequest = new Object();
    // define also all the constants
    XMLHttpRequest.UNSENT = 0;
    XMLHttpRequest.OPENED = 1;
    XMLHttpRequest.HEADERS_RECEIVED = 2;
    XMLHttpRequest.LOADING = 3;
    XMLHttpRequest.DONE = 4;
}

/** Creates new instance of the XMLHttpRequest object */
XMLHttpRequest.newInstance = function() {
    var xmlHttp = null;
    // use the ActiveX control for IE5.x and IE6
    try {
        xmlHttp = new ActiveXObject("MSXML2.XMLHTTP");
    } catch (othermicrosoft){
        try { 
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        } 
        catch (native) {
            // If IE7, Mozilla, Safari, etc: Use native object
            xmlHttp = new XMLHttpRequest();
        } 
    } 

    return xmlHttp;
};
 
Share this answer
 
Comments
NupurParashar 11-Oct-13 5:19am    
I cannot replace txt with XML as there are around 600 pages where I am using "modules.txt" filename. And XMLHTTP is used for writing XML.. If i am not wrong? I have no option other than using a txt file. So I need a way to write a txt file only.. which is cross-browser compatible.
enhzflep 11-Oct-13 5:33am    
You can request anything with an XMLHttpRequest. Although it's likely a task for later, if you've got "modules.txt" hard-coded into 600 different pages you need to review your approach - the current one couldn't reasonably be characterized as "doing it right".

This sounds like the perennial "XY problem" - that is, you have a problem, X. You see Y as a solution to X, so you ask "How do I do Y?" Far too often, a perfect solution to Y is useless, since the solution to X is actually Z.

In closing, I suggest you explain what you're trying to achieve - what is problem X?
NupurParashar 11-Oct-13 5:40am    
See its a demo project. Where we have no server side. We have to work only on client.and as far as hard-coding is concerned.. we had to do it since no databases are there and we have hard-coded the complete demo project to give overview of real product to the end customers.Even I dont have much options other than getting this ActiveXobject worked in FF.
enhzflep 11-Oct-13 6:13am    
Well, if you have 600 places you need to read/write data, you'd be much better off having 600 calls to _a function_ that read/wrote data. That way, you could replace the function body once and have it result in different functionality (or a different implementation of the same functionality)

You actually do have access to databases if your browser if HTML5 compliant. Have a look into WebSQL - it may suit your needs.

I'd love to help, but you've supplied no extra information with which to do so. Telling me why you've chosen solution Y for an (as yet) unkown to fellow readers due to "Order from Boss" still doesn't give the people you're asking for help any ability to deliver it.

Again, what are you trying to do? I really (really, really, _really_) dont care why or whom says that solution Y is the answer to problem X. In order for _me_ to be able and prepared to help, I need more info. You're perfectly entitled to wait until(if?) a better response comes from another member. :)
NupurParashar 11-Oct-13 6:50am    
Ok in your language X is I want an alternative for activeXobject which should be cross browser compatible. Please check my code I have pasted in my question. I need a code which is cross browser compatible and have to write a text file. As ActiveXobject is supported by IE only. So its not the correct approach as its not working in Firefox.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900