473,397 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Safari (Mac) - keysuppress(event) issue


The following code suppresses the 'enter' key, when run in I.E. 5.5 or
later (Windows) but not when run in Safari (Mac)

<body onkeypress="javascript:keysuppress(event)" >

function keysuppress(e)
{
if (e.type=="keypress" && e.keyCode=="13")
{
event.returnValue=false
}
}

What code can I use to suppress the 'enter' key when running an app in
Safari?

Thanks.

Jul 23 '05 #1
2 2010


Marcia Gulesian wrote:
The following code suppresses the 'enter' key, when run in I.E. 5.5 or
later (Windows) but not when run in Safari (Mac)

<body onkeypress="javascript:keysuppress(event)" >

function keysuppress(e)
{
if (e.type=="keypress" && e.keyCode=="13")
{
event.returnValue=false
}
}

What code can I use to suppress the 'enter' key when running an app in
Safari?
I don't have Safari here to test but the following hopefully works as it
uses both the W3C DOM Level 2 event handling preventDefault method and
the established return false to cancel the keypress event:

<html lang="en">
<head>
<title>keypress event handling</title>
<script type="text/javascript">
function init () {
document.onkeypress = function (evt) {
if (!evt && window.event) {
evt = window.event;
}
if (evt) {
var keyCode = evt.keyCode ? evt.keyCode :
evt.charCode ? evt.charCode : evt.which;
if (keyCode == 13) {
if (evt.preventDefault) {
evt.preventDefault();
}
return false;
}
else {
return true;
}
}
return true;
};
if (document.layers) {
document.captureEvents(Event.KEYPRESS);
}
}

init();
</script>
</head>
<body>
<form action="">
<p>
You should not be able to enter line breaks if the keypress event handling
works:
<br>
<textarea name="textareaName" rows="5" cols="80"Kibology for all.

</textarea>
</p>
</form>
</body>
</html>

Tested to work in IE 6, Netscape 7.1, Mozilla 1.7, Netscape 4.
Please report back to the group whether that solves the problem for Safari.
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 23 '05 #2
Martin Honnen wrote:

What code can I use to suppress the 'enter' key when running an app in
Safari?

<snip>
Tested to work in IE 6, Netscape 7.1, Mozilla 1.7, Netscape 4.
Please report back to the group whether that solves the problem for Safari.


Doesn't work in Safari 1.0.2, no errors.
Mick
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: sanj | last post by:
Hi all, My site is located at: http://www.eastdayspa.com/index.html I have use these main styles /* main styles */
3
by: Marcia Gulesian | last post by:
How can I make the following code run only when the cursor is in one text box and not in another? <body onkeypress="javascript:keysuppress(event)" function keysuppress(e) { if...
3
by: Marcia Gulesian | last post by:
document.getElementById("TextBox1").setAttribute("value","mm/dd/yyyy") works in Internet Explorer (Windows) but not in Safari (Mac). How can I insert a string into a textbox in the Safari browser?
7
by: aljamala | last post by:
Hi, I have a page that has a button "Exit and Close", which closes the popup window that it has opened. This works fine under IE, NN, FF and Opera but not Safari. Any ideas why? I even tried...
5
by: dvpnet | last post by:
Hi Hello, I recently created a website in IE6 using frames. My friend has a Mac, the browser is Firefox. The top frame cannot be entirely seen. Is it a Firefox or Mac issue? How can I be...
1
by: laltvm | last post by:
I have a strange issue with safari. My intention was to capture for the keystroke and increment and decrement a particular test box value by 1 or -1.The following is my code. var y=x.value...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.