You can setup a content script that does it for you that your popup
communicates with. I do it with three files:
background.html (register this in your manifest with the background_page key):
=============
function getSelection() {
chrome.tabs.executeScript(null, // by default, executes in current tab
{ file: "content_script.js"});
}
chrome.extension.onRequest.addListener(function(request) {
alert("got selection: " + request);
});
content_script.js
============
chrome.extension.sendRequest(window.getSelection());
popup.html
========
chrome.extension.getBackgroundPage().getSelection();
I haven't tested any of this, but I think it should work :)
- a
On Tue, Nov 24, 2009 at 10:13 AM, Jay <[email protected]> wrote:
> I don't think that quite works in this context. My function
> (browser_action: popup.html):
>
> <script>
> var selected_txt = window.getSelection(); <--- does not work
>
> function shareaholic(){
> chrome.tabs.getSelected( null , function(tab) {
> var shareaholicUrl =
> "http://www.shareaholic.com/share/";
> var url = encodeURIComponent(tab.url);
> var title = encodeURIComponent(tab.title);
>
> var shareaholicUrl_tab = shareaholicUrl + '?url=' +
> url + '&title='
> + title +'¬e=' + selected_txt;
> var shr_iframe = '<iframe id="shrFrame"
> name="shrFrame" src="' +
> shareaholicUrl_tab + '" noresize="noresize" frameborder="0"></
> iframe>';
> document.getElementById('shr_iframe').innerHTML =
> shr_iframe;
> });
> }
> </script>
>
>
> On Nov 24, 1:03 pm, Mohamed Mansour <[email protected]> wrote:
>> In JS, you should use window.getSelection()
>>
>> - Mohamed Mansour
>>
>> On Tue, Nov 24, 2009 at 5:39 AM, Jay <[email protected]> wrote:
>> > Hey guys,
>>
>> > Any ideas on the best way to do this? In regular JS i'd use
>> > content.getSelection(). A little lost on how to do it here.
>>
>> > Thanks in advance.
>>
>> > --
>>
>> > You received this message because you are subscribed to the Google Groups
>> > "Chromium-extensions" group.
>> > To post to this group, send email to [email protected].
>> > To unsubscribe from this group, send email to
>> > [email protected]<chromium-extensions%[email protected]>
>> > .
>> > For more options, visit this group at
>> >http://groups.google.com/group/chromium-extensions?hl=en.
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "Chromium-extensions" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/chromium-extensions?hl=en.
>
>
>
--
You received this message because you are subscribed to the Google Groups
"Chromium-extensions" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/chromium-extensions?hl=en.