function document.onkeypress(){
var keycode = null;
if (!e) var e = window.event
if (e.keyCode) keycode = e.keyCode;
else if (e.which) keycode = e.which;
if (keyCode == 10) {
if (window.getSelection) {
txt = window.getSelection().toString();
} else if (document.getSelection) {
txt = document.getSelection();
} else if (document.selection) {
txt = document.selection.createRange().text;
}
alert(txt);
}
}
raju dasa,
Excuse me,could yougive an example of
the codefor mysituation?(insertthe selected text
alert)?The fact that Ido notfind yourselfcombines these
twotasksunfortunately
ReSonance
Member
10 Points
84 Posts
processing shortcuts and Paste the selected text
Jan 23, 2013 09:02 AM|LINK
Hello, I tried to implement the processing function keys, and paste the selected text in alert. Unfortunately, this only works in IE.
<script language='JavaScript'> function document.onkeypress(){ if (window.event.keyCode == 10) { if (window.getSelection) { txt = window.getSelection().toString(); } else if (document.getSelection) { txt = document.getSelection(); } else if (document.selection) { txt = document.selection.createRange().text; } alert(txt); } } </script>Who ever so cross-platform solution for this problem?
prabu.raveen...
Contributor
5020 Points
955 Posts
Re: processing shortcuts and Paste the selected text
Jan 23, 2013 11:11 AM|LINK
Hi,
Try as below,
function document.onkeypress(){
var keycode = null;
if (!e) var e = window.event
if (e.keyCode) keycode = e.keyCode;
else if (e.which) keycode = e.which;
if (keyCode == 10) {
if (window.getSelection) {
txt = window.getSelection().toString();
} else if (document.getSelection) {
txt = document.getSelection();
} else if (document.selection) {
txt = document.selection.createRange().text;
}
alert(txt);
}
}
ReSonance
Member
10 Points
84 Posts
Re: processing shortcuts and Paste the selected text
Jan 24, 2013 01:44 AM|LINK
prabu.raveendran, Sorry, does not work
raju dasa
Star
14396 Points
2449 Posts
Re: processing shortcuts and Paste the selected text
Jan 24, 2013 06:16 AM|LINK
Hi,
Instead of onkeypress try using onkeydown / onkeyup events
(onkeypress may not works in FF)
rajudasa.blogspot.com || blog@opera
ReSonance
Member
10 Points
84 Posts
Re: processing shortcuts and Paste the selected text
Jan 24, 2013 09:35 AM|LINK
raju dasa, Excuse me, could you give an example of the code for my situation? (insert the selected text alert)? The fact that I do not find yourself combines these two tasks unfortunately
asp.netforum...
Member
604 Points
132 Posts
Re: processing shortcuts and Paste the selected text
Jan 24, 2013 09:44 AM|LINK
hai
the event.keyCode not working in firfox.Many people got the problem and changed ther mind.So change to any another way
Like:
http://forums.asp.net/t/1742290.aspx/1
http://forums.asp.net/t/1431209.aspx/1
http://forums.asp.net/t/1410653.aspx/1
raju dasa
Star
14396 Points
2449 Posts
Re: processing shortcuts and Paste the selected text
Jan 24, 2013 10:44 AM|LINK
Hi,
Try this complete code: (tested in IE, FF)
<!DOCTYPE html> <html> <head> <meta charset=utf-8 /> <title>JS Bin</title> <script> document.onkeyup = function(e){ var evt = window.event ? event.keyCode : e.which; if (evt == 10 || evt == 13) { var txt = ''; if (window.getSelection) { txt = window.getSelection().toString(); } else if (document.getSelection) { txt = document.getSelection(); } else if (document.selection) { txt = document.selection.createRange().text; } alert(txt); } } </script> </head> <body> selectMe </body> </html>rajudasa.blogspot.com || blog@opera
ReSonance
Member
10 Points
84 Posts
Re: processing shortcuts and Paste the selected text
Jan 25, 2013 01:52 AM|LINK
raju dasa, Thank you very much, this is what I had to.)) Have only to think of how to hang on another key button type submit ..