javascript prompt for password (i.e. *******)

前端 未结 4 963
再見小時候
再見小時候 2021-01-14 09:54

I\'m writing a bookmarklet and I need to be able to prompt the user for a \"password\". However, I don\'t want it to be in clear text on screen, so I cannot use prompt.

相关标签:
4条回答
  • 2021-01-14 10:21

    there isn't one - try looking into Thickbox on a modal setting like this:

    <a href="iframeModal.html?placeValuesBeforeTB_=savedValues&TB_iframe=true&height=200&width=300&modal=true" title="add a caption to title attribute / or leave blank" class="thickbox">Open iFrame Modal</a>
    
    0 讨论(0)
  • 2021-01-14 10:23

    The easy, fast answer: No, there are no cross browser method like window.prompt() that masks the user input. There are however some proprietary stuff you could look into. In MSIE you got window.createPopup(), window.showModalDialog() and window.showModelessDialog(). However I don´t reccomend using this approach =P

    What would happen if you used http authentication for your destination? Would the UA prompt the user with a un/pw?

    0 讨论(0)
  • 2021-01-14 10:32

    You can create a floating div on the current page, with a form containing a password field.

    0 讨论(0)
  • 2021-01-14 10:32

    alternative: let the bookmarlet point to a particular web page. Get the password from the user on that page, and continue.

    This solution does not use javascript at all, as you may have noticed. If you really insist on using javascript, you will have to create a new window using javascript (window.open), add form and input elements to it, and set the form's submit value to your web app backend.

    you can of course, display a dialog box on the current page, but that will be pretty irritating to the user. Be warned.

    jrh

    0 讨论(0)
提交回复
热议问题