473,893 Members | 1,571 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Safari (Mac) - keysuppress(eve nt) 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="jav ascript:keysupp ress(event)" >

function keysuppress(e)
{
if (e.type=="keypr ess" && e.keyCode=="13" )
{
event.returnVal ue=false
}
}

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

Thanks.

Jul 23 '05 #1
2 2040


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="jav ascript:keysupp ress(event)" >

function keysuppress(e)
{
if (e.type=="keypr ess" && e.keyCode=="13" )
{
event.returnVal ue=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>keypre ss event handling</title>
<script type="text/javascript">
function init () {
document.onkeyp ress = 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.preventDef ault) {
evt.preventDefa ult();
}
return false;
}
else {
return true;
}
}
return true;
};
if (document.layer s) {
document.captur eEvents(Event.K EYPRESS);
}
}

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="textareaN ame" 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
3782
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
1670
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 (e.type=="keypress" && e.keyCode=="13")
3
478
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
10511
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 checking the self.name property and this is returned blank in Safari. Any help would be appreciated. Cheers
5
1461
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 sure that my website can work with all browsers? Should I still use frames in the future? Thanks for replying !
1
983
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 var VK_UP = 38; var VK_DOWN = 40; switch (e.keyCode){ case VK_UP : { y++; break} case VK_DOWN : {y--;
0
9982
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9830
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10469
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7173
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5858
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6066
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4684
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4280
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3289
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.