Results 1 to 2 of 2

This is a discussion on create tabs in a new window within the Plugins Development section, part of the Chrome Plugins category: Hello, I got a question about opening a new window and additional tabs in that window. What I want to ...


  1. #1
    shbae is offline Junior Member
    Join Date
    Mar 2011
    Posts
    1

    Default create tabs in a new window

    Hello,
    I got a question about opening a new window and additional tabs in that window. What I want to do is that when the extension icon is clicked, a small popup is presented, where a link is shown. When the link is clicked, open multiple URLs in a new window. Here is my code:
    Code:
    <script type="text/javascript">
    function call1(){
      chrome.windows.create({url:"http://www.cnn.com"}, function (win1){
        console.log("message1");
        chrome.tabs.create({url:"http://www.yahoo.com/", windowId:win1.id});
    });
      console.log("message2");
    }
    </script>
    <body>
    <a href="javascript:call1();">Click me</a><br>
    </body>
    When the "Click me" is clicked, a new window is opened showing only cnn page, not any more tabs, although showing yahoo page is expected.

    An interesting point is that when I run the same thing under debug mode, it works as I wanted (also putting the two messages out well).

    Could anybody help me to figure this out?

  2. #2
    PAEz's Avatar
    PAEz is offline Moderator
    Join Date
    Aug 2009
    Location
    Australia
    Posts
    656

    Default

    I had a bit of a look at this for ya and it looks like you found a bug....or maybe this is how its meant to be.

    Your right, it works fine if you inspect popup and click on the link, but if you dont inspect popup then the callback is never called (unless....look below).

    There seems to be two ways for you to get around this.....

    Create Window can open more than one url, example......
    Code:
    function call1(){
      chrome.windows.create({url:["http://www.cnn.com","http://www.yahoo.com/"]});
    }
    Also, it does seem to call the callback if the callback is in the background page....which is why I wonder if this is a bug or if its expected behaviour....thing is the life of the popup is only while its visible, so after you open the other window the callback no longer exists as the popup window has closed (this is only a guess but I think it might be right).
    Heres an example of using a background page....

    Background.html
    Code:
    <script>
    function tabss(winn){
      //  console.log("message1");
        chrome.tabs.create({url:"http://www.yahoo.com/", windowId:winn.id});
    	alert("tabs");
    }
    </script>
    popup.html
    Code:
    function call1(){
      chrome.windows.create({url:["http://www.cnn.com","http://www.yahoo.com/"]},chrome.extension.getBackgroundPage().tabss);
    }

Similar Threads

  1. chrome.create.tabs not working
    By nabeca in forum Chrome Tech
    Replies: 2
    Last Post: 10-21-2010, 08:07 PM
  2. Unable to create new tabs via CTRL+T while watching Youtube vids
    By Silentlee in forum Chrome Troubleshooting
    Replies: 1
    Last Post: 09-01-2010, 05:20 AM
  3. Side tabs / Vertical tabs
    By sarjoor in forum Chrome Talk
    Replies: 4
    Last Post: 06-10-2010, 04:02 AM
  4. chrome.tabs.create problem
    By Inco in forum Plugins Development
    Replies: 1
    Last Post: 11-09-2009, 06:52 AM
  5. Closing tabs/undoing to previously closed tabs
    By sam2 in forum Chrome Plugins
    Replies: 3
    Last Post: 04-16-2009, 11:16 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •