Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8643941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:10:26+00:00 2026-06-12T12:10:26+00:00

According to this question , when we set the window.location, javascript will stop executing

  • 0

According to this question, when we set the window.location, javascript will “stop” executing or turn into a race condition.

Sometimes we need to fire window.location = SOMESCH://xxx multiple times inside a WebView to send “Notifications” back to our app. For example setting window.location = myapp://loginButtonEnabled?e=1 to tell the app that the user had filled in some nessasary info and can start login. It seems to be impossible to do something like this:

function(){
window.location = myapp://loginButtonEnable?e=1;
window.location = myapp://hideHintView;
.....
window.location = myapp://theLastThing;
}

Only the last window.location = myapp://theLastThing will be fired and then the execution of Javascript will stop(though we stopped the redirecting in our app by returning NO in webView:shouldStartLoadWithRequest:navigationType:).

I found it interesting that PhoneGap made this possible by using a dispatching queue, but I still haven’t figure out why it works, anybody knows the trick??

BTW, is there a simple way to “resume” the execution after setting location? It will be much better than using an operation queue.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T12:10:28+00:00Added an answer on June 12, 2026 at 12:10 pm

    You need to give the event loop a chance to respond to the location change each time. The typical way of doing this is using a setTimeout with a small/zero delay, which has the effect of moving execution to the next event loop tick. Try something like this:

    var q=[];
    
    function dequeue() {
      window.location='myapp://'+q.shift();
      if (q.length>0) setTimeout(dequeue,0);
    }
    
    function notifyApp(cmd) {
      q.push(cmd);
      if (q.length==1) setTimeout(dequeue,0);
    }
    
    notifyApp('loginButtonEnable?e=1');
    notifyApp('hideHintView');
    notifyApp('theLastThing');
    

    As for javascript execution stopping, setting window.location shouldn’t have this effect unless it actually results in a page change – perhaps try using the technique above and see if your javascript continues after the last notifyApp() call.

    EDIT: Another approach to this issue is to create temporary iframes instead of changing the location of the current page – see for example
    Triggering shouldStartLoadWithRequest with multiple window.location.href calls

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

According to this question on how to set the time_zone in mysql and this
According to this question it seems like you can do this for Methods. What
According to this question I succeeded to create upload image, but now I need
According to this question in order for Flymake to work you must add a
This question will undoubtedly be difficult to answer and ask in a way that
according to this question , I can't assign the result of a boolean logic
In the question Why will Visual Studio 2005 not debug my javascript? I learned
According to this question (and many many google search results), when we're in a
According this article , generic JPA DAO(Data Access Object) is a pretty nice pattern.
I didnt find anything according this issue. Can jaas be used to secure my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.