开发者

Problem with OnKeyDown and window.location in FireFox

开发者 https://www.devze.com 2023-02-16 04:29 出处:网络
I have a small script that shall redirect to another page when return is pressed in a textbox, it works fine in IE, Chrome, Safari but not in FireFox. If i attatch the Debugger in FireBug it works.

I have a small script that shall redirect to another page when return is pressed in a textbox, it works fine in IE, Chrome, Safari but not in FireFox. If i attatch the Debugger in FireBug it works.

here is my script:

<form name="form1" method="post" action="Default2.aspx" id="form1">

    <input id="ind" onkeydown="defaultButton(event)" />

    <script type="text/javascript">

        function defaultButton(event) {
            if (event.keyCode == 13) {
                event.returnValue = false;
                event.cancel = true;
                Send();
 开发者_开发技巧           }
        }

        function Send() {
            var content = document.getElementById("ind").value;

            if (content == null || content.length == 0) {
                document.getElementById("ind").focus();
                return;
            } else {
                window.location = "http://www.google.com?name=" + content;
            }
        } 
    </script>

Is thre anybody there can help med get this working cross browser? Thank very much in advance!!


You can try calling preventDefault

    function defaultButton(event) {
        if (event.keyCode == 13) {
            event.returnValue = false;

            if (event.preventDefault) {
                event.preventDefault();
            }

            Send();
        }
    }
0

精彩评论

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