www.webdeveloper.com
Results 1 to 5 of 5

Thread: [RESOLVED] Giving control back to the browser

  1. #1
    Join Date
    Mar 2011
    Posts
    37

    resolved [RESOLVED] Giving control back to the browser

    Hi,

    When I am trying to inject below javascript in to IE browser.

    Code:
    Step1: window.location = "http://www.google.com"
    Step2: document.getElementsByName("q")[0].value="Script Value"
    Javascript engine executing the first step and then before the page getting navigated to "http://www.google.com", it is trying to execute the next step.

    Since the page is not completly loded, script could not able to find the text field that it has to set and throwing an error: "Internet Explorer Script Error"

    I have tried "setTimeout" function, however the problem is: Browser taking the control back after the whole script is getting executed and then page is getting navigated to the page "http://www.google.com"

    Here I want to execute the Step1 and then give control back to the browser from my javascript file so that browser loads the page completely and then I want to take back the control then execute the Step2.

    Please guide me!!

    Thanks!!

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Quote Originally Posted by krieya View Post
    Here I want to execute the Step1 and then give control back to the browser from my javascript file so that browser loads the page completely and then I want to take back the control then execute the Step2.
    That is simply impossible. JavaScript is a client-side language, thus all the change it might provoke on the document are lost when the session changes. Even if you might reach the Step 2 (in some browsers it looks like you can), it will be of no use.

    What, in fact, is your real need? Maybe cookies might resolve it, but definitely not in this manner.

  3. #3
    Join Date
    Mar 2011
    Posts
    37
    Actually, I have kept the whole javascript code in a .htm page and I have configured the .htm to get execute upon selecting a item from IE context menu.

    Script is getting executed very fine however when i select the context menu item, control is transferred to the javascript and once the whole execution is done then only control is giving back to the browser.

    However I want it in such a way, javascript file should get execute only when the browser is in ready state and it should wait when the browser is in busy (i.e., loading) state.

    Any suggestions to get this task done?

  4. #4
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    I have asked you what you want to do, not what do you think about how that has to be done. Can you detail, in simple words? An hypothetical example, for instance.

  5. #5
    Join Date
    Mar 2011
    Posts
    37
    Sorry for that KOR, I thought it would be clear if i mention you how my script should go.

    Here is a simple example.
    I want to run a script to,
    1. Navigate to www.google.com
    2. Set search text
    3. click search button.

    here is the script.

    Code:
    <script language="javascript">
              window.location="www.google.com";
              document.getElementsByName("q")[0].value="Search Text";
              document.getElementsByName("btnG")[0].click();
    </script>
    Please suggest me how to inject the above script in to IE browser.

    I agree with your previous reply. If we run the above script from a webpage, it won't work, as soon as the page navigates to other URL, javascript will also be refreshed hence I am trying to inject the script into the browser.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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