473,549 Members | 3,099 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Making a MS jscript ECMA/DOM compliant

Now what I have is a function that only works in WinIE4+ because it's
uses Microsoft proprietary properties and methods:

Expand|Select|Wrap|Line Numbers
  1.  
  2. function gmshortcutkeys() {
  3. if ((parseInt(navigator.appVersion) >= 4) && (navigator.appName ==
  4. "Microsoft Internet Explorer")) {
  5. if (event.ctrlKey != true) return;
  6. gmselection = document.selection.createRange().text;
  7. if (window.event.keyCode == 1) {
  8. gminsertlink = prompt("What do you want to link to?",
  9. "http://")
  10. if (gminsertlink == null) return;
  11. document.selection.createRange().text = '<a href="' +
  12. gminsertlink + '">' + gmselection + '</a>';
  13. return;
  14. }
  15. if (window.event.keyCode == 2) {
  16. document.selection.createRange().text = '<strong>' +
  17. gmselection + '</strong>';
  18. return;
  19. }
  20. if (window.event.keyCode == 3) {
  21. gminsertacrotitle = prompt("How is this acronym spelled out?",
  22. "Start here")
  23. if (gminsertacrotitle == null) return;
  24. document.selection.createRange().text = '<acronym title="' +
  25. gminsertacrotitle + '">' + gmselection + '</acronym>';
  26. return;
  27. }
  28. if (window.event.keyCode == 4) {
  29. gminsertdfntitle = prompt("How is this jargon or technical
  30. term defined?", "Start here")
  31. if (gminsertdfntitle == null) return;
  32. document.selection.createRange().text = '<dfn title="' +
  33. gminsertdfntitle + '">' + gmselection + '</dfn>';
  34. return;
  35. }
  36. if (window.event.keyCode == 5) {
  37. gminsertdelcite = prompt("Point to the page responsible for
  38. this deletion.", "http://")
  39. if (gminsertdelcite == null) return;
  40. document.selection.createRange().text = '<del datetime="' +
  41. document.lastModified + '" cite="' + gminsertdelcite + '">' +
  42. gmselection + '</del>';
  43. return;
  44. }
  45. }
  46. }
  47.  
  48.  
This function HTML tags around selected text in a textarea for a CMS.
It does this in response to keyboard events thus making a simplistic,
through-the-web markup editor for textareas. For example, you select
some text in the textarea, hit a key combo and bang, your select text
is bounded by <strong> tags. Occasionally it may hit the user with a
prompt to fill in a value for the tag attribute.

Kinda quick and nifty huh?

The problem is it only works in Internet Explorer. What I'd like is
some suggestions on how to change this script so that it works in
Mozilla1, Firefox and heck maybe even Opera 7.5 or Safari. I am
completely willing to sacrifice backward compatibility with anything
less than IE6.

I'd like suggestions that bring this function into close compliance
with the W3C's DOM/ECMA rec but if I must use a little proprietary
stuff for it work in the above browsers, I'm okay with that.

Any suggestions?

Jul 23 '05 #1
4 1872


Next Generation Technologies Inc. wrote:

This function HTML tags around selected text in a textarea for a CMS.
It does this in response to keyboard events thus making a simplistic,
through-the-web markup editor for textareas. For example, you select
some text in the textarea, hit a key combo and bang, your select text
is bounded by <strong> tags. Occasionally it may hit the user with a
prompt to fill in a value for the tag attribute. The problem is it only works in Internet Explorer. What I'd like is
some suggestions on how to change this script so that it works in
Mozilla1, Firefox and heck maybe even Opera 7.5 or Safari.


Mozilla (since 1.3) has its own API to manipulate the selection in a
HTML textarea control, see
<http://www.faqts.com/knowledge_base/view.phtml/aid/13562/fid/130>
I think Opera has nothing for that so far. Don't know about Safari.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
I don't know about Opera but Mozilla provides:

- 1. the selectionStart and selectionEnd properties on a textarea, plus
the setSelectionRan ge() method;

- 2. most of the Range portion of W3C's "Document Object Model (DOM)
Level 2 Traversal and Range Specification"
(http://www.w3.org/TR/DOM-Level-2-Traversal-Range), in which, for example,

document.select ion.createRange ().text
becomes:
window.getSelec tion().getRange At(0).toString( )

Don't overlook any simple answers, though: I still find the best way to
add stuff in the middle of a textarea is

var obj = document.forms[0].textarea1;
var str = obj.value;
obj.value = str.substring(0 , 5) + "<newtag/>" + str.substring(6 );

For events, Mozilla uses the W3C standard
(http://www.w3.org/TR/DOM-Level-2-Events), in which you starting
intercepting events with addEventListene r([type], [function], [begin]).
Jul 23 '05 #3
Martin,

Well I'd rather avoid Mozilla's API if it is proprietory. What I want
is a cross-platform, DOM-compliant way to do what the script above
does.

But if I can't have that, I guess I could do a sniff and route the
client to the method that works for their browser.

Jul 23 '05 #4
Paul,
var obj = document.forms[0].textarea1;
var str = obj.value;
obj.value = str.substring(0 , 5) + "<newtag/>" + str.substring(6 );


I don't quite understand this here. Doesn't this code seem to require
that I already explicitly know the length of the string I want to
bound?

What I want is:

1) To dynamically select a string with my mouse or with the keyboard
2) Hit a key combo and have JavaScript bound the selected string with
the HTML tags associated with that key combo.

Basically the code I cited at that start of this thread is a
simple-minded, non-WYSIWYG, keyboard driven markup editor of sorts that
I use with my blogging tool. I've moved to Firefox and the above code
no longer works.

Jul 23 '05 #5

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

Similar topics

4
5851
by: Harag | last post by:
Hi All I currently thinking of converting from my little knowledge of VBscript to jScript ASP. With this in mind I'm looking at my current code to see how it will convert over to Jscript. One thing I have spotted that I can't think of a way round is the ADO recordset.GetRows command.
14
2800
by: John Bentley | last post by:
Note this is crossposted to comp.lang.javacript and microsoft.public.dotnet.scripting. After some Googling and FAQing my understanding of these terms is, crudely: Javascript (3 different definitions): 1. The scripting language originally developed by Netscape. (I offer a Brief handle: "Original Netscape Script") 2. The current...
10
2102
by: Gernot Frisch | last post by:
Hi, I have found some menu functions. It works quite well, but how can I replace it with a simple <a href> if javascript is turned off? I reduced my code to: <script>IncludeMenuHere()</script> More, any tips about "fading" the menu item in and out (x-browser)? Currently it's using DIVs and this.items.visibility(false);
10
8329
by: Danny | last post by:
In the classic asp, I can use escape built-in function (server side function) like this: <script language=javascript> var myContent = unescape(<%=escape(strContent)%>) </script> How do I do that in asp.net? Seems like escape server side function is no longer provided in asp.net, or am I missing something here?
15
1881
by: Sam Kong | last post by:
Hello! I got recently intrigued with JavaScript's prototype-based object-orientation. However, I still don't understand the mechanism clearly. What's the difference between the following two? (1)
28
5255
by: Andre | last post by:
Hi, Does anyone know whether the ECMA, or an other standard document, specifies a maximum for the value that can be pass to the setTimeOut() function in Javascript? Andre
37
3528
by: pochartrand | last post by:
Hello, Is there a way to manipulate or at least read the pseudo-class of an element ? I know the style attribute can be accessed and gives the CSS properties for a particular element. However, I can't seem to access the "hover" properties. example :
10
1677
by: the DtTvB | last post by:
I heard it is not the same. The lastest version of JavaScript is 1.6 while lastest version of JScript is 8.0 I also heard a little bit about ECMAScript, but I still don't know what's the difference of them. So, what's exactly the difference of it?
4
1885
by: Lando | last post by:
I'm a bit confused ...javascript and jscript are the same thing ? javascript and java are related.......... javascript in windows differs from javascript in linux....? Sorry,... if some question could be stupid . Many thanks.
0
7520
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...
0
7718
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7470
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6041
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5088
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...
0
3498
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...
0
3480
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1058
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.