Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to change the keyboard type when using the prompt() Javascript function when using Mobile Safari on the iPhone?

Mobile Safari on the iPhone allows you to specify different keyboard types for text input boxes as demonstrated in the Safari How-To's for iPhone, here. However, I'm wondering if it's possible to change keyboard type displayed when a Javascript prompt() dialog is displayed.

I know I can roll my own modal pop-up if I have to, but I'd like to know if it's possible to use the built-in prompt() function with a different keyboard (numeric, in my case).

like image 334
Gabe Hollombe Avatar asked Oct 15 '22 12:10

Gabe Hollombe


1 Answers

I am pretty sure the answer is, unfortunately, "no". Consider the following experiment:

<html>
<head>
 <script type="text/javascript">
   function doit() {
     prompt("this is a test");
   }
 </script>
</head>
<body>
 <a href="javascript:doit();">Click me</a>
</body>
</html>

If you put that into an HTML page and load it into Mobile Safari, then turn your phone into landscape view, then click on the link, what do you expect to happen? What you'd expect to happen is for the prompt dialog to come up in landscape orientation with the wide keyboard. What actually happens is that Mobile Safari rotates back to portrait view and pops up the small keyboard, then rotates back after you enter your text. (For fun, alert the results, the alert rotates the display too...) Note that the HTML 5 customizations (type="tel" or pattern="[0-9]*") properly pop up landscape keyboards when appropriate.

Note that this is not a priori evidence that you can't customize the keyboard's appearance, but it is a pretty strong indicator that the javascript prompt behavior is bolted on and not well integrated into the rest of the user experience.

like image 100
ddoughty Avatar answered Oct 26 '22 23:10

ddoughty