简体   繁体   中英

Chrome Extension form submit

what I want to do, is to create call a function which can create a form and submit it every time a specific page is called.eg

function foo(url){
  var form = document.createElement("form");
  var input1 = document.createElement("input");
  var input2 = document.createElement("input");

  form.method = "POST";
  form.action = url;
  form.name = "myForm";
  form.id = "form_id";

  input1.type = "hidden";
  input1.value = "value";
  input1.blahblah...

  input2.type = "hidden";
  input2.value = "value";
  input2.blahblah...

  form.appendChild(input1);
  form.appendChild(input2);
  document.body.appendChild(form);

  form.submit();

  alert("Form submitted");
}

The thing is that, even since the form is appended in the document, the submit is not working for some reason. (alert never comes up);

Any ideas where the problem is?

(or any alternative to do this)

Thanks

 function foo(url) { var form1 = document.createElement("form"); var input1 = document.createElement("input"); var input2 = document.createElement("input"); form1.method = "POST"; form1.action = url; form1.name = "myForm"; form1.id = "form_id"; input1.type = "hidden"; input1.value = "value"; input2.type = "hidden"; input2.value = "value"; form1.appendChild(input1); form1.appendChild(input2); document.body.appendChild(form1); form1.submit(); alert("Form submitted"); } 

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