Maybe .stop
does not execute because it will only be processed in the loading of the page and not in the download, I can not state with conviction this because I'm not sure of the behavior in different browser engines (webkit, blink, trident, gecko , etc), but some ways you could choose are to use cookies or the parameters in the querystring (so it does not affect POST).
Assuming your form is something like:
<form action="?send=1" method="POST">
...
<input type="submit" value="">
</form>
And in JavaScript check:
<script type="text/javascript">
//Verifica se tem o GET com "expressão regular"
if (/\?send=1(&|$)|&send=1(&|$)/.test(window.location)) {
$("#enviar").click();
}
</script>
Or if your page uses PHP you can check if one of the POST fields was sent (or rather all) using isset
:
<?php if (!isset($_POST['campo1'], $_POST['campo2'], $_POST['campo3'])): ?>
<script type="text/javascript">
$("#enviar").click();
</script>
<?php endif; ?>
The !isset($_POST['campo1'], $_POST['campo2'], $_POST['campo3'])
contains !
and isset
, is a negation, ie if there is no field1, field2, field3, it means that it did not come from your FORM and then it will execute .click
, of FORM will not go into the IF and will not run again.
Set the values within isset
to the fields in your FORM.