2013-10-03 49 views
0

我正在开发一个Chrome扩展,它将检查在后台选项卡中打开了哪个网站,然后解析它。但是我不知道为什么表单中的提交按钮不起作用,即使这是在我开发的一种类似的扩展中工作。提交按钮在Chrome扩展中不起作用

下面是HTML代码

<html> 
<head> 
    <script src="fetcher.js"></script> 
</head> 
<body style="min-width:250px; "> 
    <form name="login" action="http://localhost/CD/worker.php" style="padding:15%" method="GET"> 
    <fieldset> 
     <legend>CD</legend> 
     <div id="tag"></div> 
     <p> 
      <label for="name"></label> 
      <br /> 
      <input type="hidden" id="name" name="val" class="text" size="20" /> 
     </p> 

     <p> 
      <button type="submit" class="button positive"> 
      <img alt="ok" src= 
      "/tick.png" /> 
      Login 
      </button> 
     </p> 
    </fieldset> 
    </form> 
</body> 

,这里是我的JavaScript文件

window.addEventListener("load", windowLoaded, false); 
function windowLoaded() { 
    chrome.tabs.getSelected(null, function(tab) { 
     //doing stuff with the url 
     var url=tab.url; 

     if(url.indexOf(".com")>0) 
      var n=url.split(".com"); 
     else if(url.indexOf(".co.in")>0) 
      var n=url.split(".co.in"); 
     else 
      var n=url.split(".in"); 

     var m=n[0].split("."); 
     n=m[m.length-1].split("://"); 
     var qstr=n[0]; 

     document.getElementById("tag").innerHTML="Get Coupons for "+qstr; 
     document.getElementsByName("val").value=""+qstr;  
    }); 
} 

PHP文件

<?php 
    $name=$_GET['val']; 
    echo $name; 
?> 
+1

是'check()'defined? –

+1

Off topic topic error:style =“padding = 15%” – isherwood

+0

@Jamie,是的,我很抱歉!我正在测试一些东西。我编辑了代码。 –

回答

1

我能得到我的提交按钮与t合作他如下:

document.querySelector("form").addEventListener("submit", function(event) { 
    event.preventDefault(); 
    //do stuff 
});