最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - IE7 form not prompted for remember password when submitted through javascript - Stack Overflow

programmeradmin8浏览0评论

I have a website where we use Javascript to submit the login form. On Firefox it prompts the user to remember their password, when they login, but on IE7 it doesn't.

After doing some research it looks like the user is only prompted in IE7 when the form is submitted via a Submit control. I've created some sample html to prove this is the case.

<html>
<head>
<title>test autoplete</title>
<script type="text/javascript">
function submitForm()
{
    return document.forms[0].submit();
}
</script>
</head>
<body>
<form method="GET" action="test_autoplete.html">
<input type="text" id="username" name="username">
<br>
<input type="password" id="password" name="password"/>
<br>
<a href="javascript:submitForm();">Submit</a>
<br>
<input type="submit"/>
</form>
</body>
</html>

The href link doesn't get the prompt but the submit button will in IE7. Both work in Firefox.

I can't get the style of my site to look the same with a submit button, Does anyone know how to get the remember password prompt to show up when submitting via Javascript?

I have a website where we use Javascript to submit the login form. On Firefox it prompts the user to remember their password, when they login, but on IE7 it doesn't.

After doing some research it looks like the user is only prompted in IE7 when the form is submitted via a Submit control. I've created some sample html to prove this is the case.

<html>
<head>
<title>test autoplete</title>
<script type="text/javascript">
function submitForm()
{
    return document.forms[0].submit();
}
</script>
</head>
<body>
<form method="GET" action="test_autoplete.html">
<input type="text" id="username" name="username">
<br>
<input type="password" id="password" name="password"/>
<br>
<a href="javascript:submitForm();">Submit</a>
<br>
<input type="submit"/>
</form>
</body>
</html>

The href link doesn't get the prompt but the submit button will in IE7. Both work in Firefox.

I can't get the style of my site to look the same with a submit button, Does anyone know how to get the remember password prompt to show up when submitting via Javascript?

Share Improve this question asked Oct 1, 2008 at 16:16 Jason GritmanJason Gritman 5,3114 gold badges31 silver badges38 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 5

Why not try hooking the form submission this way?

<html>
    <head>
        <title>test autoplete</title>
        <script type="text/javascript">
            function submitForm()
            {
                    return true;
            }
        </script>
    </head>
    <body>
        <form method="GET" action="test_autoplete.html" onsubmit="return submitForm();">
            <input type="text" id="username" name="username">
            <br>
            <input type="password" id="password" name="password"/>
            <br>
            <a href="#" onclick="document.getElementById('FORMBUTTON').click();">Submit</a>
            <br>
            <input id="FORMBUTTON" type="submit"/>
        </form>
    </body>
</html>

That way your function will be called whether the link is clicked or the submit button is pushed (or the enter key is pressed) and you can cancel the submission by returning false. This may affect the way IE7 interprets the form's submission.

Edit: I would remend always hooking form submission this way rather than calling submit() on the form object. If you call submit() then it will not trigger the form object's onsubmit.

Did you try putting in url in the href and attaching a click event handler to submit the form and returning false from the click handler so that the url does not get navigates to.

Alternatively hidden submit button triggered via javascript?

You could try using the HTML <button> tag instead of a link or a submit button.

For example,

<button type="submit">Submit</button>

The <button> tag is much easier to style than the standard <input type="submit">. There are some cross-browser quirks but they are not insurmountable.

A really great article about the use of <button> can be found at particletree: Rediscovering the button element

发布评论

评论列表(0)

  1. 暂无评论