How can I move the inline scripts for my search out into a separate js file?

Viewed 183

I have a search bar on my page, but I need to move the code out into a separate js file in order to submit everything as a google browser extension. Right now it's written like this in the HTML:

<html>

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>Search</title>
  <link rel="stylesheet" type="text/css" href="popup.css" />
</head>

<body>

  <div id="searchContainer">
    <script type="text/javascript">
      function dos12(g1) {
        window.open('https://www.google.com/#q=' + g1, '_self', 'G1window');
      }
    </script>

    <form onsubmit="dos12(this.g1.value); return false;">
      <input id="field" type="text" name="g1" size="20" placeholder="Google Search" autofocus="autofocus" />
      <div id="delete"><span id="x">x</span></div>
      <input id="submit" name="submit" type="submit" value="Search" />
    </form>
  </div>

</body>

</html>

I have moved other scripts out of the HTML and into js files, and put in <script src=> in their place, but this one has the form, onsubmit, and G1 value that I can't wrap my head around.

Any help would be massive. I have spent many hours so far :/

1 Answers

If I have understood the requirement correctly, you want something like this (Source code). I created a similar kind of extension long time back, this should be helpful.

The important thing you need to do is, use the 'chrome_url_overrides' property to override the new tab with the html page you create. (Check out the manifest.json file)

"chrome_url_overrides" : {
    "newtab": "index.html"
  }

Rest is similar to creating a web application.

Related