Script Execution

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Rsmastermind
    New Member
    • Sep 2008
    • 93

    Script Execution

    Hi all,

    I am executing a code here is the description of that........

    [CODE=javascript]function abc(){


    window.open(som e file name with parameter and in different frame)//Line 1
    alert('anything ');
    .............
    .............//then acessing dom of that opened frame and doing operation

    }[/CODE]

    The problem is it gives alert first and then it loads the page in the frame.
    But even then it is not doing operation on the DOM.

    But I had checked if i am commenting the Line 1 then the code is operating
    on the already loaded page in the target frame.

    So I want to know that is there any sequence of executing the Javascript
    or In this language there is preference to some special API.









    }
    Last edited by gits; Sep 18 '08, 02:18 PM. Reason: added code tags
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    dom operations could just be executed after! the dom is ready ... so you could open the window and assign the code that should be executed to the onload of the document that is to be loaded in this window.

    kind regards

    Comment

    • Rsmastermind
      New Member
      • Sep 2008
      • 93

      #3
      Originally posted by gits
      dom operations could just be executed after! the dom is ready ... so you could open the window and assign the code that should be executed to the onload of the document that is to be loaded in this window.

      kind regards
      But in the first line I am loading that DOM.In the second line I am executing the code.Also If I am using different functions for this purpose.
      Like
      In function 1() I am loading that page and calling function 2() from function 1()
      then also the problem is same.

      If the problem will be there then what should I do?

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        ... i cannot see this usage from the posted code ... could you post it please so that i could have a closer look at it? open.window() doesn't load the dom already it just opens a window and then the document will be loaded ...

        kind regards

        Comment

        • Rsmastermind
          New Member
          • Sep 2008
          • 93

          #5
          Originally posted by gits
          ... i cannot see this usage from the posted code ... could you post it please so that i could have a closer look at it? open.window() doesn't load the dom already it just opens a window and then the document will be loaded ...

          kind regards
          ok

          [CODE=javascript]function abc()
          {

          window.open('pq r.html','name of the frame','');
          var labelId=top.fra mes[name of the frame].document.getEl ementsByTagName (someTag);
          labellength=lab elId.length;
          for(i=0;i<label length;i++){

          doing some operation

          }
          }[/CODE]
          Last edited by gits; Sep 18 '08, 02:57 PM. Reason: added code tags

          Comment

          • gits
            Recognized Expert Moderator Expert
            • May 2007
            • 5390

            #6
            i guess that you want to retrieve the nodes in the opened document? in this case the function should look something like this:

            [CODE=javascript]function abc() {
            var foo = window.open('te st.html', 'foobar');

            foo.onload = function() {
            var labelId = document.getEle mentsByTagName( 'input');
            labellength = labelId.length;

            for (var i = 0; i < labellength; i++) {
            alert(i);
            }
            }
            }[/CODE]
            note that the code is assigned to the onload-handler of the window that is opened by the script.

            kind regards

            Comment

            Working...