The async
property sets or gets whether a
script should be executed asynchronously.
This property maps to the async
attribute of the <script> tag.
async |
Yes | 10.0 | Yes | Yes | Yes |
Return the async property.
var v = scriptObject.async
Set the async property.
scriptObject.async=true|false
Value | Description |
---|---|
true|false | Specifies whether a script should be executed asynchronously.
|
A Boolean type value, returns true if the script is executed asynchronously, otherwise it returns false.
The following code shows how to check if a script was executed asynchronously.
<!DOCTYPE html>
<html>
<body>
<script id="myScript" src="demo_async.js" async></script>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<!-- w w w. jav a 2s.c o m-->
<script>
function myFunction() {
var x = document.getElementById("myScript").async;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows: