简体   繁体   中英

Unable to submit form in chrome extension

I am not able to submit form in chrome extension.

When did i try to submit form, then whole page is refreshing instead of submit data and get the result.

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:

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:

   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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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