Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

chrome extension: open new tab from a form in popup

I have a simple javascript form in a chrome extension popup. When clicking the extension icon, the user fills the form and clicks "go!", which should open a new tab - the URL for this new tab will be determined according to values in the form.

Currently the popup shows fine and the form values are populated fine. How do I open the tab when the user clicks the button?

(I am pretty new with javascript and the documentation confused the hell out of me :| )

manifest.json:

{
  "name": "My Helper",
  "version": "1.0",
  "description": "My Helper",
  "background_page" : "background.html",
  "browser_action": {
    "default_icon": "icon.png",
    "popup": "popup.html"
  },

  "permissions": 
     ["tabs"]
}

popup.html:

<html>
<head>
      <script type="text/javascript">
              // some functions...
      </script>
</head>

<body>
      <form name="frmOne">
            // input fields
            <button type="button" onclick="buildTheUrl(..input values..)">Go!</button>
      </form>
</body>
</html>

background.html is currently empty.

like image 626
Galz Avatar asked Apr 16 '11 20:04

Galz


1 Answers

chrome.tabs.create({url: 'http://pathToYourUrl.com'});
like image 142
Tim Joyce Avatar answered Nov 07 '22 05:11

Tim Joyce