Web Analytics Made Easy -
StatCounter Change current dir in JS - CodingForum

Announcement

Collapse
No announcement yet.

Change current dir in JS

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Change current dir in JS

    Is it possible to change the current directory in javascript?

    This is for pages that will be on CD.

    Thanks.

  • #2
    how do you mean?
    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

    i am a loser geek, crazy with an evil streak,
    yes i do believe there is a violent thing inside of me.

    Comment


    • #3
      Er, exactly what i said!

      Comment


      • #4
        ...

        what is it, that you want to accomplish, by changing the directory? for the most part, you don't "change" directories in javascript or html
        bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

        i am a loser geek, crazy with an evil streak,
        yes i do believe there is a violent thing inside of me.

        Comment


        • #5
          javascript is used on the web u know. if you want to interact with things like directorys you will have to use jscript (microsoft "ripoff" of javascript) with the windows scripting host (or WSH) shell object to get to use files and folders (and some other system functions which arent available from the web. and also you sill need to use these in a HTA application (that seems to be joh6nn's speciality) which are just html applications
          photoshop too expensive? use the GIMP! www.gimp.org

          Comment


          • #6
            this is the code

            function HL(URL)
            {
            var ts,all,rng

            //all = new String();
            //fso = new ActiveXObject("Scripting.FileSystemObject");
            //ts = fso.OpenTextFile(URL,1);
            //all = ts.readAll();
            //ts.close();

            //parent.frames('searchmain').document.clear();
            //parent.frames('searchmain').document.write(all);

            parent.frames('searchmain').location.href = URL

            rng = parent.frames('searchmain').document.body.createTextRange();

            for (var i=0; rng.findText(g_keyword)!=false; i++)
            {
            if (rng!=null)
            rng.pasteHTML("<FONT color=yellow style='BACKGROUND-COLOR: midnightblue'>" + rng.text + "</font>");
            }
            delete all
            delete fso
            }

            This code does not do what it is supposed to do, which is highlight all instances of g_keyword. Spend a little time looking at the code and putting in a few alerts() and it is easy to see why - the for loop is being executed before the page is fully loaded, so it is creating a text range on the existing page, not the new one.

            The commented code was the previous method I used - which opens the htm file manually and pastes all of it's text into the frame. The words DO get highlighted using this method, however, as the location.href property is not being set, the "current directory" as i called it, for that frame is not being set, so the relative paths to images and css files, for example, are not preserved. Consequently, images are not shown.

            Having the ability to change the "current directory" would alleviate this problem I think.

            Another solution is to put in a delay() put this doesn't work.

            thanks for the help anyway. and don't be fooled by the junior member status. or senior member status for those who patronise.

            Comment


            • #7
              First, I would wait for the document you load into your frame "searchmain" to load completely. Can be done by assigning its onload eventhandler a reference to a sepearte function, which handles the creation of the textrange.

              Prior to highlighting the keywords, I would compare the location.pathname of the document in the frame "searchmain" and compare it to the location.pathname of the page where the frameset is defined. Let your script see if the directory structure differs and if so, make repeated use of String.replace() to replace parts of the value in the src and href attributes of your image/css tags.

              The details of such a script can only be guessed from afar, but basically that's an approach you should consider. By doing that, you don't "change" a directory, you rather manipulate the URLs in your freshly loaded document.

              Alternatively, you could make use of the onerror event of images; there are some threads in the general javascript forum about assigning a new image source by using that event. But AFAIR that won't work for stylesheets...

              (BTW, I don't get your comment about the junior member status. You expect others to mindread? )
              De gustibus non est disputandum.

              Comment

              Working...
              X