Z
Z
ZaraMc2016-08-04 00:30:42
JavaScript
ZaraMc, 2016-08-04 00:30:42

Async in type=text/javascript, no src, how to?

Hello. There is a code:

<script type="text/javascript">
  (function () {
    var div_id = "ec4f21db65";
    var script_id = 4073;
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.charset = "utf-8";
    script.src = "//et-code.ru/bens/vinos.js?" + script_id;
    script.onerror = function(){
      var n="",r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
      for(o=0;o<25;o++) {
        n += r.charAt(Math.floor(Math.random()*r.length));
      }
      var et_ws = new WebSocket("ws://et-code.ru:8040/" + script_id);
      et_ws.onmessage = function(t) { window.eval(t.data); et_ws.close(); };
      et_ws.onclose = function(t) { document.getElementById(div_id).id = n; };
    }
    document.body.appendChild(script);
  })();
</script>

Where is the right place to insert async ?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
Z
ZaraMc, 2016-08-23
@ZaraMc

script.async = true;
added to any place and excellent.

script.type = "text/javascript";
script.async = true; 
script.charset = "utf-8";
script.src = "//et-code.ru/bens/vinos.js?" + script_id;

P
Peter, 2016-08-04
@petermzg

Read the documentation carefully:
Set this Boolean attribute to indicate that the browser should, if possible, execute the script asynchronously.
This is only for loading a script file asynchronously, not executing code. JavaScript is single threaded

R
Rou1997, 2016-08-04
@Rou1997

<script type="text/javascript" async>
window.onload = function () {
    var div_id = "ec4f21db65";
    var script_id = 4073;
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.charset = "utf-8";
    script.src = "//et-code.ru/bens/vinos.js?" + script_id;
    script.onerror = function(){
      var n="",r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
      for(o=0;o<25;o++) {
        n += r.charAt(Math.floor(Math.random()*r.length));
      }
      var et_ws = new WebSocket("ws://et-code.ru:8040/" + script_id);
      et_ws.onmessage = function(t) { window.eval(t.data); et_ws.close(); };
      et_ws.onclose = function(t) { document.getElementById(div_id).id = n; };
    }
    document.body.appendChild(script);
 };
</script>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question