473,287 Members | 3,295 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,287 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 2006


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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.