DoA
08-08-2009, 04:58 PM
Hi guys,
I've got a script that is working with linked text but I want it to work with both already linked text <a href> and user selected text.... in Firefox by the way (It's gonna be a FF addon)
Here's how I'm calling the function -
<menuitem id="myid" label="MyLabel" accesskey="C"
insertafter="context-stop" oncommand="myFunction();"/>
and here's the (working) function that uses a hyperlink -
function myFunction() {
try {url = gContextMenu.linkURL} // new FF, other?
catch(e) {
try {url = gContextMenu.linkURL()} // old FF, SM, other?
catch(e) {url = String(gContextMenu.link)} // either FF, other?
}
window.open('http://myurl.com/file.php?url=' + url, 'window name')
}
Here's the code for the user selected portion that I want to integrate.
function foo() {
var selObj = window.getSelection();
alert(selObj);
var selRange = selObj.getRangeAt(0);
// do stuff with the range
}
Is it possible to do it in one function or do I need two - in which case is it possible to call 2 functions simultaneously?
I've got a script that is working with linked text but I want it to work with both already linked text <a href> and user selected text.... in Firefox by the way (It's gonna be a FF addon)
Here's how I'm calling the function -
<menuitem id="myid" label="MyLabel" accesskey="C"
insertafter="context-stop" oncommand="myFunction();"/>
and here's the (working) function that uses a hyperlink -
function myFunction() {
try {url = gContextMenu.linkURL} // new FF, other?
catch(e) {
try {url = gContextMenu.linkURL()} // old FF, SM, other?
catch(e) {url = String(gContextMenu.link)} // either FF, other?
}
window.open('http://myurl.com/file.php?url=' + url, 'window name')
}
Here's the code for the user selected portion that I want to integrate.
function foo() {
var selObj = window.getSelection();
alert(selObj);
var selRange = selObj.getRangeAt(0);
// do stuff with the range
}
Is it possible to do it in one function or do I need two - in which case is it possible to call 2 functions simultaneously?