开发者

any method to change title of inputbox i.e prompt in javascript

开发者 https://www.devze.com 2022-12-19 01:02 出处:网络
i want to know if there i开发者_如何学Gos any way to change title of inputbox i.e prompt in javascript?nope, you cannot change the title in the native javascript prompt. you could easily write a funct

i want to know if there i开发者_如何学Gos any way to change title of inputbox i.e prompt in javascript?


nope, you cannot change the title in the native javascript prompt. you could easily write a function of your own, though, which mimics the behavior of the prompt, but the flow won't be exactly the same (i.e. you'll have to use callbacks, rather than a return value, for the user input)

Something like:

function myPrompt(title, message, value, callback) {

    // create form, that displays the title, message, and an input box with the value

    // append the form to the dom, probably in some elevated (modal) manner

    // if the user invoking myPrmopt didn't specify a callback, don't register listeners
    if(typeof callback != 'function') return;

    // register listeners:

    // if there's a close button, equivalent to escaping out of a prompt:
    closeBtn.click(function() { callback() }); // not passing any params

    okBtn.click(function() { callback(input.value); });

}


If you are talking about changing the title of the window itself, then what i know it is not possible because this method has only two parameters which do not affect the title of the window. See this for more information.

Syntax:

prompt(msg,defaultText)

But you can not change the title which says"

 "page at whatever address says...."

Note: The title varies in different browsers.


No, and not only that: you can't really use prompt any more, at all.

IE7 has removed it(*), ostensibly on security grounds. (I find Microsoft's reasoning somewhat spurious on this, especially compared to a lot of the questionable stuff IE has come up with in the past. But it's too late to complain about now.)

So today, for compatibility, you must use an in-document pop-up that runs asynchronously, with a callback function run on completion, similar to David's example. There are many pre-packaged scripts that will do this for you, but it does require that you re-write your calling code to deal with the response in an inline callback function instead of executing directly after the function call.

In any case, alert/confirm/prompt aren't great for usability (as they make the rest of the browser UI unresponsive), aren't very pretty, and have some sneaky concurrency issues in some browsers. If you can get rid of them for all but the most trivial cases (or debugging purposes), that's all for the better.

(*): actually it's still there, but hidden by a security warning infobar which silently prevents it working for at least the first time. This effectively makes the feature as good as useless.


inputbox.title="insert your text here ?";

0

精彩评论

暂无评论...
验证码 换一张
取 消