从chrome扩展中的输入框中获取值

时间:2018-03-31 19:07:26

标签: javascript google-chrome-extension

在我的Chrome扩展程序中,只有2页 - popup.html result.html 。 两个页面具有相同的ID,具有相同的ID。表单包含1个输入框和一个提交按钮。

我面临三个问题

  1. 我必须点击按钮才能使其正常工作。我不行时不行 打进去。
  2. 我无法更改变量的值 globalURL
  3. 我无法检索那个输入框值 出现在popup.html上
  4. 我是新手并试图解决过去2天的问题。在stackoverflow上有很多解决方案,在google上没有适合要求的

    请帮助!!

    Manisfest -

     {
      "manifest_version": 2,
      "name": "Seolyzer",
      "description": "Analyze your websites now.",
      "version": "1.0",
      "browser_action": {
        "default_icon": "icon.png",
        "default_popup": "popup.html"
      },
    
      "background": {
        "scripts": ["assets/js/jquery.js", "assets/js/myapp.js"]
      },
      "permissions": [
        "webRequestBlocking",
              "webRequest",
              "*://*.google.com/",
              "<all_urls>",
        "storage",
        "tabs",
        "http://*/*",
              "https://*/*"
            ],
     "js": ["content.js"]
    }
    

    Popup.html

     <!DOCTYPE html>
        <html>
        <head>
            <title>-Result</title>
            <script src="assets/js/jquery.js"></script>
            <script src="assets/js/boostrap-mini.js"></script>
            <script src="assets/js/myapp.js"></script>
        </head>
        <body> 
            <form class="form-inline" method="post"  id="domain1" action="result.html" target="_blank">
                <div class="input-group">
                <input type="text" required="required" name="domain" placeholder="Enter your domain here" class="form-control input-lg" id="domain inputlg" style="height:49px;font-size:larger;">
               <div class="input-group-btn" style="width:1%;">
                <button type="submit" class="btn btn-success" id="urlbutton" style="height:49px;"><i class="glyphicon glyphicon-stats">&nbsp</i>Analyze it</button>
                       </div> </div>    
                   </form>
    
        </body>
        </html>
    

    Result.html

    <!DOCTYPE html>
    <html>
    <head>
        <title>-Result</title>
        <script src="assets/js/jquery.js"></script>
        <script src="assets/js/boostrap-mini.js"></script>
        <script src="assets/js/myapp.js"></script>
    </head>
    <body> 
        <form class="form-inline" method="post"  id="domain1" action="result.html" target="_blank">
            <div class="input-group">
            <input type="text" required="required" name="domain" placeholder="Enter your domain here" class="form-control input-lg" id="domain" style="height:49px;font-size:larger;">
           <div class="input-group-btn" style="width:1%;">
            <button type="button" class="btn btn-success" id="urlbutton" style="height:49px;"><i class="glyphicon glyphicon-stats">&nbsp</i>Analyze it</button>
                   </div> </div>    
               </form>
    
    </body>
    </html>
    

    Myapp.js

    var globalURL="google.com"
    
          $(function(){
              $('#urlbutton').click(function(){
            var urll="facebook.com";
    globalURL= urll;
            if(urll)
            {
    
             console.log("New "+ urll); 
            }
            else
            {
              console.log("no");
    
              }
    
            })})
    console.log(globalURL);
    

0 个答案:

没有答案