Safari "TypeError - Undefined value" with bookmarklet, need advice

O

OtisUsenet

Hi,

I have a bookmarklet that works perfectly in Firefox, IE, Konqueror,
and Opera, but in Safari 2.0.3 (417.9.2) it doesn't work. I enabled
debugging and I can see "TypeError - Undefined value" reported in the
Javascript console, but I'm not sure where the error is.

The bookmarklet in question is here:

javascript:if (parseInt(navigator.appVersion) >= 4) { if
(navigator.userAgent.indexOf('MSIE') > 0) { q =
document.selection.createRange().text; } else if
(navigator.userAgent.indexOf('Safari') > 0) { q =
document.selection.createRange().text; } else { q =
document.getSelection(); } if (!q) { void(q = prompt('Enter
keywords to search your Simpy Links:', '')); } if (q) {
location.href='http://www.simpy.com/simpy/LinkSearch.do?q=' +
encodeURIComponent(q); }}

I tried changing the "document.selection.createRange().text" bit in the
case of Safari to "document.getSelection()", but that didn't work
either, the error being "TypeError - Value undefined (result of
expression document.getSelection) is not object".

Does anyone know how to get the selected text under Safari?

If anyone's interested, this bookmarklet is from Simpy -
http://www.simpy.com/simpy/BrowserBookmarklets.do

Any help would be very appreciated. Thank you!
 
O

OtisUsenet

A possible solution: window.getSelection() instead of
document.selection.createRange().text and document.getSelection().

Is that the right thing to do for Safari?

Thanks.
 

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

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top