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

  • SEARCH
  • Home
  • 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 8907835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:01:09+00:00 2026-06-15T03:01:09+00:00

I’m debugging an issue and found strange behavior in how Firefox and Safari deal

  • 0

I’m debugging an issue and found strange behavior in how Firefox and Safari deal with the onclick JavaScript.

Here is my code:

<form id="createMessageForm" action="onclick.php?refresh=<?php echo ++$_REQUEST['refresh'];?>" method="post" >
<input type="hidden" id="iteration" value="1"/>
</form>
<a href="page2.html" target="_blank" onclick="document.getElementById('createMessageForm').submit();return true;">Hello</a>

Loading this in Firefox, it always opens ‘page2’ for me. But loading this in Safari, it only open the ‘page2’ for me about 1 in 10 times, or less. It’s like depends on whether the browser can finish the ‘return true;’ statement before the form got submitted or not.

I thought JavaScript is always single-threaded, so what’s the expected behavior in such code?

  • 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-15T03:01:10+00:00Added an answer on June 15, 2026 at 3:01 am

    Javascript is single-threaded as you say. However it is also happy to work asynchronously.

    HTTP requests are async events in javascript because they can take an unknown amount of time to complete. Javascript makes the call to the HTTP request and then carries on with whatever else it has to do until the HTTP request completes and returns control back to Javascript (or in this case, completes and triggers the browser to load the new page).

    In your case, you’re basically firing two HTTP requests from Javascript, one right after the other. The second is fired because Javascript doesn’t wait for the first to respond; it just carries on to the next one. The unpredictable results you’re seeing are basically the result of whichever of the two HTTP requests completes its response first, to the point of getting the browser to load the new page.

    This is also how AJAX works — the ‘A’ in AJAX stands for Asynchronous. Javascript makes the HTTP request, and will happily carry on doing whatever else you want of it. The HTTP request is handled by the browser, which triggers an event for Javascript to pick up when the request is ready. That’s why with AJAX calls you need to give it a ‘success’ function, rather than just saying if(success) in the next line of code.

    And that leads me to a suggestion to solve your problem. Fire the form submission as an AJAX event. That way, the browser will never try to load it as a new page when it responds. You can still tell the browser to trigger the separate page load immediately afterwards if you like, although I would suggest waiting for the first call to finish, as otherwise you won’t know whether it has actually succeeded.

    Hope that gives you some help.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am reading a book about Javascript and jQuery and using one of the
I used javascript for loading a picture on my website depending on which small
I have a small JavaScript validation script that validates inputs based on Regex. I
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from

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.