Delaying Execution of jQuery Function

Fingerprintjs2 readme says:

You should not run fingerprinting directly on or after page load. Rather, delay it for a few milliseconds to ensure consistent fingerprints. See #307, #254, and others.

Here is a test case to delay the execution of hello world jQuery program.

<html>
<head>
<title>jQuery Delay</title>

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>

</head>
<body>
<script type="text/javascript">

$(document).ready(function(){
    function showHello() {
       $("#msgid").html("This is Hello World by JQuery");
    }
    setTimeout(showHello, 2000);
});

</script>

This is Hello World by HTML

<div id="msgid"></div>

</body>
</html>

This will delay the execution of showHello function by 2 seconds. Using delay to get the fingerprint will result in consistent values when the backend is hit several times.


Related Articles


Create your own user feedback survey