Problem with insert_link()

A

AwefulService

The following code was from one of the posts, its caller looks like
this:
<form ...
<input type="button" name="txtBold" onclick="insert_link('noteid2');"
value="Link">
....
</form>
however, the caller failed with FireFox 2. Is it because of the
setup/config with my FF2 or?
With IE7, the caller works, however, a URL length exceeds about 50
chars, the link's "head" and "tail" would be chopped off, that is, no
<a and no /a>, hence, rendering it unusable. How come? Any way to
fix it?

Many thanks.

function insert_link(e) {
var str = document.selection.createRange().text;
document.getElementById(e).focus();
var my_link = prompt("Enter URL:","http://");
if (my_link != null) {
var sel = document.selection.createRange();
sel.text = "<a href=\"" + my_link + "\" target=_new>" + str + "</a>";
}
return;
}
 
P

pr

The following code was from one of the posts, its caller looks like
this:
<form ...
<input type="button" name="txtBold" onclick="insert_link('noteid2');"
value="Link">
...
</form>
however, the caller failed with FireFox 2. Is it because of the
setup/config with my FF2 or?

No. See below.
With IE7, the caller works, however, a URL length exceeds about 50
chars, the link's "head" and "tail" would be chopped off, that is, no
<a and no /a>, hence, rendering it unusable. How come? Any way to
fix it?

Don't know about that one. Can you provide the URL of a test page?
function insert_link(e) {
var str = document.selection.createRange().text;

There's no such thing as document.selection.createRange() in Firefox.

I presume you are trying to retrieve/set a selection in a textarea (or
text input), in which case in Firefox you will need to retrieve a
substring of the textarea's value using its selectionStart and
selectionEnd properties, set the entire value afresh and use
setSelectionRange() to restore the selection.

There's an example at <URL:
http://developer.mozilla.org/en/docs/Code_snippets:Miscellaneous#Inserting_text_at_the_cursor>

It always helps if you describe what you're trying to do and the exact
error message(s) you see, if any - use Tools, Error Console in Firefox.
 
A

AwefulService

Thank you so much, please see my comments below.

No. See below.


Don't know about that one. Can you provide the URL of a test page?
I've figured it out, it's related to RegExp for the data display...

Currently it's not released yet, will be later, thanks for your
understanding.
There's no such thing as document.selection.createRange() in Firefox.

So, is there some equivalent js for FF?
 
J

Joost Diepenmaat

Thank you so much, please see my comments below.



So, is there some equivalent js for FF?

Yes.

See http://developer.mozilla.org/en/docs/DOM:Selection
And http://www.w3.org/TR/DOM-Level-2-Traversal-Range/ranges.html

Note that there are many significant differences between how IE handles
selections & ranges and the w3 DOM. There are probably also some
differences between the w3 dom and Gecko, but those are relatively
minor if all you're doing is selecting some text.

See also: http://www.quirksmode.org/dom/range_intro.html

Joost.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,145
Messages
2,570,826
Members
47,373
Latest member
Desiree036

Latest Threads

Top