[giving up keeping this on chromium-discuss]
Aha, I didn't look closely enough at the bookmarklet to see it was
trying to get the title and url of the current page. The first pass of
the tab API is complete now (yay rafaelw!). So you can do something
like:
chrome.tabs.getCurrent(null, function(tab) {
// do something with tab.title and tab.url
});
So I guess the complete (untested) code would look like:
<div class="toolstrip-button" onclick="gmailThis()"><span>Gmail
This</span></div>
<script>
function gmailThis() {
chrome.tabs.getSelected(null, function(tab) {
var url = "http://mail.google.com/mail/?ui=1&view=cm&fs=1&tf=1&to=&su=" +
encodeURIComponent(tab.title) + "&body=" +
encodeURIComponent(tab.url);
var w = window.open(url, 'addwindow',
,'status=no,toolbar=no,width=575,height=545,resizable=yes');
setTimeout(function() {
w.focus();
}, 200);
});
}
</script>
On Mon, Jun 1, 2009 at 10:28 AM, Mohamed Mansour <[email protected]> wrote:
> Aaron, correct, but doesn't each extension run in its own page? So if you
> execute that onclick it will think the document.title and document.url is
> the extension page itself. Hence,
> chrome-extension://0000000000000000000000000000000000000000/hello_gmail.html
> But the tabs API isn't complete (I assume, unless its a bug) so there is no
> way to get the current selectedTab as I explained in the previous email.
> That Tab struct has the url/title which is needed to make it work as an
> extension.
> -- Mohamed Mansour
>
>
> On Mon, Jun 1, 2009 at 12:43 PM, Aaron Boodman <[email protected]> wrote:
>>
>> There is a bug in the code. The string %20250 needs to have single
>> quotes around it. If you add that, it works.
>>
>> But there are better ways to write this since you're not constrained
>> to fit it all into a single javascript statement like you are with
>> bookmarklets. You can learn how by just doing some quick searches for
>> HTML, JavaScript, and onclick. There are many online tutorials.
>>
>> - a
>>
>> On Mon, Jun 1, 2009 at 9:34 AM, Zak <[email protected]> wrote:
>> >
>> > Mohamed Mansour posted some code too, and suggested that I should use
>> > the Tabs API to accomplish this, but that it is incomplete. I don't
>> > really know how to utilize the code he posted.
>> >
>> >
>> >
>> >
>> > On Jun 1, 12:22 pm, Aaron Boodman <[email protected]> wrote:
>> >> bcc: chromium-dev
>> >> cc: chromium-discuss
>> >>
>> >> Can you send the code for the complete toolstrip?
>> >>
>> >> - a
>> >>
>> >>
>> >>
>> >> On Sun, May 31, 2009 at 4:57 PM, Zak <[email protected]> wrote:
>> >>
>> >> > Hi,
>> >>
>> >> > I'm really not a coding person, but I followed the documentation
>> >> > here:
>> >>
>> >> >http://dev.chromium.org/developers/design-documents/extensions/howto
>> >>
>> >> > and set up an extension. Instead of hello-world.html I put an html
>> >> > file containing a script (a gmail-this-page bookmarklet). The code is
>> >> > below:
>> >>
>> >> > [code]
>> >> > javascript:(function(){m='http://mail.google.com/mail/?
>> >> > ui=1&view=cm&fs=1&tf=1&to=&su='+encodeURIComponent(document.title)
>> >> > +'&body='+encodeURIComponent(document.location);w=window.open
>> >> >
>> >> > (m,'addwindow','status=no,toolbar=no,width=575,height=545,resizable=yes');s
>> >> > etTimeout
>> >> > (function(){w.focus();},%20250);})();
>> >> > [/code]
>> >>
>> >> > When I click the extension on the bottom bar, it just opens up an
>> >> > html
>> >> > page with that code written in plain text. Obviously I'm missing some
>> >> > crucial step, and since I don't have a background in coding or
>> >> > programming of any sort, I'm pretty lost. Evidently putting the
>> >> > javascript in an html file is a wrong move - a different filetype
>> >> > maybe?
>> >>
>> >> > Thanks. And ignore me if I'm wasting your time or whatever, I realize
>> >> > I'm some newbie guy asking probably a dumb question, but I'd
>> >> > appreciate any help getting this simple thing working.
>> > >
>> >
>>
>> >>
>
>
--~--~---------~--~----~------------~-------~--~----~
Chromium Developers mailing list: [email protected]
View archives, change email options, or unsubscribe:
http://groups.google.com/group/chromium-dev
-~----------~----~----~----~------~----~------~--~---