By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,548 Members | 1,735 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,548 IT Pros & Developers. It's quick & easy.

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

P: n/a
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!

Aug 6 '06 #1
Share this Question
Share on Google+
1 Reply


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

Is that the right thing to do for Safari?

Thanks.

OtisUsenet wrote:
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!
Aug 6 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.