Alright, so I bit the bullet and turned my javascript into an
extension so that I can use chrome.windows and chrome.tabs API.

Now the problem is that new tabs come up in the same window where I'm
running the extension, rather in a new window I just created. Keep in
mind, I'm going to create a bunch of windows, each with a bunch of
tabs, so this has to work.

Here's an example of the main code of the extension, for a simple case
where I want to open one new window and then add a second tab to that
window:

<script type="text/javascript">
chrome.windows.create({url: "http://www.google.com/"});
chrome.windows.getLastFocused(function (window) {
    chrome.tabs.create({url: "http://www.gmail.com/";, windowId:
window.windowId});
});
</script>

I'm trying to do this using getLastFocused() and a callback, since I
could not figure out how to pass the window.windowId out of the first
windows.create call. The result is not what I wanted: The "gmail" tab
ends up in the window where I run the extension, rather next to the
new "google" tab in the new window.

Any ideas?? I'm totally lost here.

On Oct 28, 2:38 pm, Aaron Boodman <[email protected]> wrote:
> There is no way to do this on purpose. Web pages should not be able to
> control whether windows or tabs are opened with that much detail. That
> is a user preference.
>
> - a
>
>
>
> On Wed, Oct 28, 2009 at 2:33 PM, reikred <[email protected]> wrote:
>
> > Any other ideas on how to get around the problem of opening tabs
> > versus opening windows? For example, if there was a way to get
> > to the variable that controls this behavior, that would work for me.
>
> > On Oct 28, 11:37 am, Aaron Boodman <[email protected]> wrote:
> >> No, the chrome.tabs API is only for use by extensions.
>
> >> - a
>
> >> On Wed, Oct 28, 2009 at 9:59 AM, reikred <[email protected]> wrote:
>
> >> > I'm trying to make a javascript that will open a bunch of windows,
> >> > each with a bunch of specific tabs.
>
> >> > <html>
> >> > <body>
> >> > <script type="text/javascript">
> >> > //The reason I cannot use windows.open() is that I do not know how to
> >> > //turn on/off whether windows.open will make a tab or a window.
> >> > chrome.windows.create({url:"http://www.google.com/"});
> >> > chrome.tabs.create({url:"http://www.gmail.com/"});
> >> > chrome.tabs.create({url:"http://www.google.com/finance/"});
> >> > //
> >> > chrome.windows.create({url:"http://www.yahoo.com/"});
> >> > chrome.tabs.create({url:"http://mail.yahoo.com/"});
> >> > chrome.tabs.create({url:"http://finance.yahoo.com/"});
> >> > </script>
> >> > </body>
> >> > </html>
>
> >> > As you see in the comment , I do not know how to get windows.open to
> >> > switch between opening windows and opening tabs, so I thought I'd try
> >> > something like chrome.tabs.create. But that does not work, and
> >> > apparently the reason is that a plain javascript does not have direct
> >> > access to this API.
>
> >> > chrome.windows.create({url:"http://www.google.com/"});
> >> > [Exception] TypeError: Cannot call method 'create' of undefined
>
> >> > How do I get access to the API? I *think* one way might be to create
> >> > an extension, but I would *really* like to avoid having to do that.
--~--~---------~--~----~------------~-------~--~----~
Chromium Discussion mailing list: [email protected] 
View archives, change email options, or unsubscribe: 
    http://groups.google.com/group/chromium-discuss
-~----------~----~----~----~------~----~------~--~---

Reply via email to