473,320 Members | 2,097 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,320 software developers and data experts.

Writing HTML tags around highlighted form text in Safari

Hi

I'm trying to write a system in which you can highlight some text in a form
box, click a button (or press a key combination) and the text highlighted
gets surrounded by a given html tag.

The following works fine in IE on a PC:
txt = document.selection.createRange().text;
document.selection.createRange().text = '<b>' + txt + '</b>';
I gather that Safari "doesn't do" document.selection.createRange().text, so
I'm using window.getSelection() instead.

I can use the following to demonstrate for myself that safari is "seeing"
the highlighted text in the form box:
txt = window.getSelection();
alert(txt);
window.getSelection() = '<b>' + txt + '</b>';
The last line is doing nothing though. I've also tried:
window.getSelection().text = '<b>' + txt + '</b>';
but no luck.

Any ideas how I can write HTML tags around some highlighted text in Safari?

Thanks for any help,

Julian
Jul 23 '05 #1
2 1779
VK
> In Safary
txt = window.getSelection();
alert(txt);


Would be greate to hear from experienced Safary victime (I'm victimized
by Windows :) But from the first look Safary simply implemented the
ancient NN4.x method. In this case getSelection()
1) is read only
2) it's just selected text on the page, with no correlation to the
actual node position.

So if you have a text ( where [ ] mark the selected text):

<p>Something just to show the problem and why this [problem] cannot be
solved.</p>

and you try to use DOM methods to locate the right node based on the
selectedText() value, you will get the first "problem" (because it
stays first), not the selected one.

If Safari *really* doesn't have any more serious methods than this,
then just screw on it until it will grow up a bit.

Jul 23 '05 #2
VK wrote:
In Safary
txt = window.getSelection();
alert(txt);


Would be greate to hear from experienced Safary victime


good hunting ;-)

Robi "one pun in ten did" :-)
Jul 23 '05 #3

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

Similar topics

3
by: Christophe Guillon | last post by:
Hello I would like to have a hypertext link which, when I click on it, leads to a web page where a certain word is highlighted. Depending on the link, the same target page would be displayed but...
6
by: sentinel | last post by:
Hi, I’m trying to modify a DHTML editor that parses a style-sheet via PHP and instead of modifying the tags via execCommand(), find a way of writing inline styles by way of adding <span style=>...
385
by: Xah Lee | last post by:
Jargons of Info Tech industry (A Love of Jargons) Xah Lee, 2002 Feb People in the computing field like to spur the use of spurious jargons. The less educated they are, the more they like...
17
by: Eric Lindsay | last post by:
Is learning to write CSS a better use of time than finding and using a package that produces complete web pages? I've moved to a new platform (Macintosh), taking with me about 400 personal web...
10
by: Eric Lindsay | last post by:
This may be too far off topic, however I was looking at this page http://www.hixie.ch/advocacy/xhtml about XHTML problems by Ian Hickson. It is served as text/plain, according to Firefox...
2
by: justplain.kzn | last post by:
Hi, I have a table with dynamic html that contains drop down select lists and readonly text boxes. Dynamic calculations are done on change of a value in one of the drop down select lists. ...
0
digicrowd
by: digicrowd | last post by:
http://bytes.com/images/howtos/applemail_sig_icon.jpg At first glance, it may not appear that Apple Mail (otherwise known as Mail.app) supports the use of HTML signature emails. However, with a...
9
by: dhtml | last post by:
I have written an article "Unsafe Names for HTML Form Controls". <URL: http://jibbering.com/faq/names/ > I would appreciate any reviews, technical or otherwise. Garrett --...
6
by: L. Ximenes | last post by:
Greetings, I've recently been struggling with the idea of writing an XML document based on user-submitted content using javascript. Using various instances of document.write on a newly opened...
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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
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...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.