In general, this code only works in Firefox 54, in all other browsers does not work. What could be the problem?

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ function fingerprint() { var canvas = document.createElement('canvas'); var ctx = canvas.getContext('2d'); var txt = "browser"; ctx.textBaseline = "top"; ctx.font = "14px 'Arial'"; ctx.textBaseline = "alphabetic"; ctx.fillStyle = "#f60"; ctx.fillRect(125,1,62,20); ctx.fillStyle = "#069"; ctx.fillText(txt, 2, 15); ctx.fillStyle = "rgba(102, 204, 0, 0.7)"; ctx.fillText(txt, 4, 17); var strng=canvas.toDataURL(); document.body.appendChild(canvas); var hash=0; if (strng.length==0) return 'nothing!'; for (i = 0; i < strng.length; i++) { char = strng.charCodeAt(i); hash = ((hash«5)-hash)+char; hash = hash & hash; } return hash; } var search = fingerprint(); $("input[type=text]").val(search); $(function(){ $(document).on('submit', '[data-action="adds"]', function (e) { e.preventDefault(); $.ajax({ url: this.action, type: this.method, data: $(this).serialize() }).done(function (data) { }); }); }); }); </script> <form name="form" id="form" action="view_text.php" method="POST" data-action="adds"> <input type="text" name="search" value=""> <input type="submit" value="GO"> </form> <script type="text/javascript"> window.onload = function() { document.forms["form"].submit(); } </script> 

In the file view_txt.php hundred code to put a string in the file, an empty value is entered.

But if without automatic form submission, then everything works fine in all browsers.

    1 answer 1

    Try instead

     window.onload = function() { document.forms["form"].submit(); } 

    to write

     $(function(){ $('#form').submit(); }); 

    It may be that the page has already loaded, but jquery has not started yet.

    • Thanks a lot, did I do everything right to get a fingerprint? It simply does not change as a user agent or IP? - emtecif