admin管理员组

文章数量:1287785

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.

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.

Share Improve this question asked Apr 16, 2011 at 20:37 GalzGalz 6,8425 gold badges35 silver badges39 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 11
chrome.tabs.create({url: 'http://pathToYourUrl.'});

本文标签: javascriptchrome extension open new tab from a form in popupStack Overflow