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 6555397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:48:55+00:00 2026-05-25T12:48:55+00:00

In most browsers (including older versions of Safari), the Javascript prompt function returns null

  • 0

In most browsers (including older versions of Safari), the Javascript prompt function returns null when the user clicks “Cancel”, and the empty string if the user clicks “Ok” with nothing in the text box. But in Safari 5.1, it returns the empty string for both cases.

I used Safari’s “report a bug” feature to report it to Apple, but who knows when they might even acknowledge it much less fix it. Does anyone have a workaround?

  • 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-05-25T12:48:56+00:00Added an answer on May 25, 2026 at 12:48 pm

    I’ve managed to come up with a real workaround, since Safari added support for showModalDialog() in 5.1. Awfully convenient, that.

    First, create a file with this content:

    <html>
    <head>
    <title>Prompt</title>
    <script type="text/javascript">
    function a(){
            if(window.dialogArguments.length > 0)
                    document.getElementById('a').textContent = window.dialogArguments[0]+'\n\n';
            if(window.dialogArguments.length > 1)
                    document.getElementById('b').value = window.dialogArguments[1];
            document.getElementById('b').focus();
    }
    
    function s(b){
            window.returnValue=b?document.getElementById('b').value:null;
            window.close();
    }
    
    function kp(e){
            if(!e.DOM_VK_ENTER) e.DOM_VK_ENTER=13;
            if(!e.DOM_VK_RETURN) e.DOM_VK_RETURN=13;
            if(!e.DOM_VK_ESCAPE) e.DOM_VK_ESCAPE=27;
    
            switch(e.keyCode){
              case e.DOM_VK_ENTER:
              case e.DOM_VK_RETURN:
                if(e.preventDefault) e.preventDefault();
                if(e.stopPropagation) e.stopPropagation();
                e.returnValue = false;
                e.cancelBubble = true;
                s(1);
                return false;
    
              case e.DOM_VK_ESCAPE:
                if(e.preventDefault) e.preventDefault();
                if(e.stopPropagation) e.stopPropagation();
                e.returnValue = false;
                e.cancelBubble = true;
                s(0);
                return false;
    
              default:
                return true;
            }
    }
    </script>
    <body style="text-align:center;white-space:pre-wrap" onload="a()">
    <span id="a"></span>
    <input type="text" id="b" onkeydown="return kp(event)" /><input type="button" value="Ok" onclick="s(1)" /><input type="button" value="Cancel" onclick="s(0)" />
    </body>
    </html>
    

    Then, for broken versions of Safari (there seems to be no way to feature-detect this without popping up a prompt and asking the user to hit “Cancel”, so you’ll probably have to do a User-Agent check), execute the following Javascript to replace window.prompt:

    (function(){
            if(window.console && window.console.log)
                    window.console.log('Applying bugfix for Safari 5.1\'s prompt()');
            var oldprompt = window.prompt;
            window.prompt = function() {
                    return showModalDialog(location.protocol+'//'+location.host+'/js/safari-5.1-bugfix.html', arguments);
            };
            window.prompt.$orig = oldprompt;
    })();
    

    Of course, change the path /js/safari-5.1-bugfix.html to the correct path to the above-created HTML file on your server. Unfortunately, we cannot use a data: URI as Safari apparently has another bug where it loses window.dialogArguments and ignores window.returnValue for dialogs with data: URIs.

    You can then use prompt() as you normally would.

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

Sidebar

Related Questions

The URL which points to the user coopthink which works in most browsers, including
Most people talk about progressive enhancement right now as serving browsers with javascript (enhanced
Most browsers cache form input values. So when the user refreshes a page, the
Working with the method setFixed() returns a string in most browsers, but sometimes I
Most of the tutorials that I've read on arrays in JavaScript (including w3schools and
In most browsers on linux, CTRL +(WHEEL)SCROLL allows the user to zoom in and
I have very strange issue, on most browsers (ie, ff, chrome, safari). Here is
It looks like in most browsers, an <input type=submit> treats both [spacebar] and [enter]
I have a jQuery select which works in most browsers axcept IE. The code
Most popular browsers, while rendering an image, they display it line-by-line top-to-bottom as it

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.