Link to home
Start Free TrialLog in
Avatar of Zack
ZackFlag for Australia

asked on

Pipe output of javascript function (Long Shot)

Heyas,

I was wondering I have the following bit a .js code:

------------------

function DisplaySearch(searchtext, condition, filter) {
    //if the mode is 'no-contents' and we are in live mode, then display the contents window and hide the page window
    //    if (document.getElementById("imgedit") == null && document.getElementById("divcontents").offsetWidth == 0)
    //        {
    //        document.getElementById("tdcontentswrapper").style.display = "table-cell"
    //        document.getElementById("tdcontentswrapper").style.width = "250px"
    //        //document.getElementById("tdpagewrapper").style.width = "70%"
    //        }
    //    //If the contents window is visible then show the search window
    //    alert("divcontents width = " + document.getElementById("divcontents").offsetWidth)
    //    if (document.getElementById("divcontents").offsetWidth != 0)
    //        {
    //Show the search results window with the loading animation
    document.getElementById("divsearchresults").style.backgroundImage = "url(../_engine/images/loading.gif)";
    document.getElementById("divsearchresults").style.backgroundRepeat = "no-repeat";
    document.getElementById("divsearchresults").style.backgroundPosition = "center center"
    //hide Contents
    document.getElementById("divcontents").style.display = "none";
    //hide properties window
    document.getElementById("divproperties").style.display = "none";
    //document.getElementById("TreeView1").style.height="100%";
    //hide index
    document.getElementById("divindex").style.display = "none";
    document.getElementById("divindex").innerHTML = "";
    //show the search results window
    document.getElementById("divsearchresults").style.display = "";
    //Set the height of the search results window so that the scrollbars will work
    //document.getElementById("divsearchresults").style.height=document.getElementById("divcontents").style.height;
    document.getElementById("divsearchresults").style.height = "100%";
    //Change the contents heading (if the control exists)
    if (document.getElementById("tdcontentslabel") != null) {
        document.getElementById("tdcontentslabel").style.display = "none";
        document.getElementById("tdindexlabel").style.display = "none";
        document.getElementById("tdsearchresultslabel").style.display = "";
    }
    //hide the contents controls
    if (document.getElementById("tdcontentscontrols") != null) {
        document.getElementById("tdcontentscontrols").style.display = "none";
    }
    //Show the close icon
    if (document.getElementById("tdCloseContentsWindow") != null) {
        document.getElementById("tdCloseContentsWindow").style.display = "";
        if (document.getElementById("tdeditcontents") != null) { document.getElementById("tdeditcontents").style.display = "none" }
    }
    if (document.getElementById("txtAdvancedSearch") != null) {
        document.getElementById("txtAdvancedSearch").focus();
    }
    //        }

    //       //if the condition was specified, then set it now
    //               if (document.getElementById("lstSearchCondition") != null && condition != "") {
    //                   document.getElementById("lstSearchCondition").value = condition;
    //               }

    //Get search results index using AJAX
    var http = false;
    var reqstring = "action=search";
    reqstring = reqstring + "&searchtext=" + searchtext;
    reqstring = reqstring + "&projectname=" + GetProjectName();
    //Search Filter
    if (document.getElementById("lstSearchFilter") != null) {
        reqstring = reqstring + "&searchfilter=" + document.getElementById("lstSearchFilter").value
    }
    else if (filter != "" && filter != null) {
        reqstring = reqstring + "&searchfilter=" + filter
    }

    //Search Condition
    if (document.getElementById("lstSearchCondition") != null) {
        reqstring = reqstring + "&searchcondition=" + document.getElementById("lstSearchCondition").value
    }
    else if (condition != "" && filter != null) {
        reqstring = reqstring + "&searchcondition=" + condition
    }
    reqstring = reqstring + "&username=" + document.getElementById("txtactiveusername").value;
    reqstring = reqstring + "&password=" + document.getElementById("txtactivepassword").value;
    if (navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }
    http.onreadystatechange = function() {
        if (http.readyState == 4) {
            if (http.status == 200) {
                //alert("tdcontents width = " + document.getElementById("tdcontents").offsetWidth);
                if (document.getElementById("tdcontents").offsetWidth == 0) {
                    //If the contents window is hidden then load search results into page window
                    document.getElementById("divpage").innerHTML = http.responseText;
                }
                else {
                    //If the contents window is visible then load search results into the contents window
                    document.getElementById("divsearchresults").innerHTML = http.responseText;
                }
                //hide the progress bar
                document.getElementById("divsearchresults").style.backgroundImage = "";
            }
            else {
                alert("Error: " + http.status + http.responseText);
            }
        }
    }
    http.open("POST", "../_engine/ajaxaction.aspx", true);
    http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

    http.send(reqstring);

------------------------

As you can see it calls some asp.net code server now since I don't have project files for code I can't create any server side scripting. Is their anyway I could get the output of the searchtxt variable to pipe to a txt file on the client side or am just shooting in the dark.

Thank you
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Javascript is not allowed to access the local file system for security reasons.  Basically to keep others from accessing your local computer without your permission.
Avatar of Zack

ASKER

Hi Dave,

So I would have to build a separate program to pipe the results to and then use that program to output the results to file. Is this correct?

Thank you.
I don't understand.  Javascript in a browser isn't allowed to save a file on the local machine.  It can communicate with the server.  Actually nothing in a browser is allowed to do that.  If you need to save something on the local machine, it will need to be a program that runs on the local machine with the permissions of the user that is running it.
ASKER CERTIFIED SOLUTION
Avatar of ahoffmann
ahoffmann
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Zack

ASKER

Cheers for the info.