Forum Moderators: open
I'm not very versed in JS, so I hope someone can help me out... I am trying to write a bookmarklet that pop-ups a list of smilies, and upon clicking on one, a "smilie code" is inserted into the currently focused text area.
The "currently focused" part is very important, since there are several text areas on the page that the smilie could be inserted into, and I have no way of editing the page itself (it's supposed to be an add-on for Movable Type and I do not want to hack the system itself.)
Right now I got this code for my bookmarklet:
javascript:t=document.activeElement.name;
void(window.open('http://URL_TO_MY_SITE?selected='+escape(t),'smiliepopup',
'scrollbars=yes,width=400,height=520,status=yes,
resizable=yes,scrollbars=yes')) This works just fine in Internet Explorer, but in Opera the pop-up doesn't open at all, I am assuming because Opera does not know the "activeElement" function?
Is there any way to get the name of the active element that works in most current browsers, or failing that, is there a way to make other browsers open the popup at least and just pass on an empty string for the "selected" variable?
Thank you for your time! :)
cheers,
Kathrin
I don't have a full solution for you, but here are some comments that may help you clarify what you want to do.
First, according to this page at Microsoft [msdn.microsoft.com], there is no public standard for "activeElement".
In other words, you're using an object that is proprietary to Microsoft's jscript, and not a part of the ECMAscript standard. So Opera will probably not be the only browser to hiccup on your code.
So you'll probably do well to sniff for the actual object you want to use - if (document.activeElement) {<take some action>}
Also, here's an idea from the FAQTs website [faqts.com] that shows an approach to creating the needed object for Netscape 6. It probably works in NN7 and recent Mozilla as well - and who knows, maybe even Opera. Worth a test, I'd say.