0

I have been working on Chrome extension and am having problems. What I'm trying to do: when you click on the icon to the right of the search bar, a search bar comes up which you type your query in and hit enter. It will then go to http://dev.bukkit.org/search/?search=(whatever was entered). This is what I have but it is not working.

<scriptLANGUAGE="JavaScript">
function whatURL() {
window.location= 'http://dev.bukkit.org/search/?search=' + document.form1.url.value;
}
</SCRIPT>

<FORM name=form1>
<inputtype="text"id="url">
<inputtype="button"id="btnSearch"value="Search"onClick="return whatURL()"/>
</FORM>

Thank you:) Note: I have the manifest and everything, its just the javascript part thats not working. EDIT: Rewrote it now it works!!!

<html>
<head>
  <script>
    function onLoad() {
      document.getElementById("mytextfield").focus();
    }

    function onKeyPress(e) {
      if (e.keyCode == 13) {
        openResults();
      }
    }

    function openHomePage() {
      window.open("http://dev.bukkit.org/");
    }

    function openResults() {
      window.open("http://dev.bukkit.org/search/?search=" + encodeURIComponent(document.getElementById("mytextfield").value));
    }
  </script>
</head>
<body onload="onLoad();">
  <img src="png-3.png" onclick="openHomePage();" style="border-width: 0px; cursor: pointer" /><br>
  <div name="myFormDiv" style="center: 6px;">
  <br>
    <input type="search" id="mytextfield" name="mytextfield" value="Search..." onkeypress="onKeyPress(event);" />

  </div>
 </div>
</body>
</html>
spongebob
  • 8,370
  • 15
  • 50
  • 83
hawkfalcon
  • 652
  • 1
  • 12
  • 24

1 Answers1

1

Try changing...

<inputtype="button"id="btnSearch"value="Search"onClick="return whatURL()"/>

to..

<inputtype="button"id="btnSearch"value="Search"onClick="whatURL()"/>

window.location doesn't need to be returned to anything. You're already making the window point to your given url when you execute window.location = "http://myurl.com"

Aidanc
  • 6,921
  • 1
  • 26
  • 30
  • Okay I tried this, it works now when you run it as a html file in browser, but only when you hit submit, not when you hit enter;/ and it still doesn't work when i upload it as a extension in chrome. – hawkfalcon Apr 26 '12 at 00:09
  • @iHawk Yes, it will only work when you hit enter. You'd have to add a listener for that. check: http://stackoverflow.com/questions/905222/javascriptenter-key-press-event – Aidanc Apr 26 '12 at 00:13
  • @iHawk also, what do you mean it doesn't work when you upload it as a extension in chrome? – Aidanc Apr 26 '12 at 00:14
  • @iHawk If I understand you correctly, you're saying it doesn't work as a extension but does as a html page? try changing `window.location = "page.html" ` to `window.location.href="page.html";` – Aidanc Apr 26 '12 at 00:24