简体   繁体   English

无法以chrome扩展名提交表单

[英]Unable to submit form in chrome extension

I am not able to submit form in chrome extension. 我无法以chrome扩展名提交表单。

When did i try to submit form, then whole page is refreshing instead of submit data and get the result. 我什么时候尝试提交表单,然后整个页面都在刷新,而不是提交数据并得到结果。

Manifest.js: Manifest.js:

{
    "name": "BrowserExtension",
    "version": "0.0.1",
    "manifest_version": 2,
    "description" : "Description ...",
    "browser_action": {
        "default_icon": "icon.png" ,
        "default_title": "That's the tool tip"
    },
    "background": {
        "scripts": ["js/jquery-2.1.4.min.js", "background.js"],
        "persistent": false
    },
    "content_scripts": [{
        "matches": ["http://*/*", "https://*/*"],
        "js": ["js/jquery-2.1.4.min.js", "content.js"]
    }],
    "permissions": [
          "tabs", 
           "activeTab",    
           "https://www.irctc.co.in/eticketing/loginHome.jsf"
        ]
}

background.js: background.js:

chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
   if(changeInfo.status == 'complete')
   {

   if(tab.url === 'https://www.irctc.co.in/eticketing/mainpage.jsf')
   {
        chrome.tabs.executeScript(null, {file: "js/autofillMain.js"});
   }

   }
});

Autofillmain.js: Autofillmain.js:

   var userName = document.getElementById("jpform:fromStation");
    userName.value = "PUNE JN - PUNE";

    var password = document.getElementById("jpform:toStation");
    password.value = "GWALIOR - GWL";

    var date = document.getElementById("jpform:journeyDateInputDate");
    date.value = "30-08-2015";

    $("#jpform").submit();'

Please let me know if you need any other information. 如果您需要其他任何信息,请告诉我。

That site's form probably relies on the submit button being clicked to run some necessary code in the click handler. 该网站的表单可能依赖于单击提交按钮才能在点击处理程序中运行一些必要的代码。

Try calling the submit button's click() explicitly, something like this: 尝试显式调用提交按钮的click(),如下所示:

  • via jQuery: $("#jpform [type='submit']:not([disabled])").click() 通过jQuery: $("#jpform [type='submit']:not([disabled])").click()
  • via standard js: document.querySelector("#jpform [type='submit']:not([disabled])").click() 通过标准js: document.querySelector("#jpform [type='submit']:not([disabled])").click()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM