I am trying to delay the loading of this chat script on my website but cannot get it to work for some reason.
console.log(script) returns the correctly dynamically generated script but for some reason the script (live chat) is not running on the page.
I have removed some content for privacy but here is my code:
HTML
<!DOCTYPE html>
<%@ LANGUAGE="VBSCRIPT" %>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta name="robots" content="noindex, nofollow">
<meta content="width=device-width, initial-scale=1, shrink-to-fit=no" name="viewport">
<meta name="description" content="Website Description">
<title>Website</title>
<link rel="alternate" href="https://www.website.com/website" hreflang="x-default"/>
<link rel="canonical" href="https://www.website.com/website">
<!--#INCLUDE VIRTUAL="/codeanalytics/google.htm"-->
<!--#INCLUDE VIRTUAL="/_borders17/assets/css-files.html"-->
<!--#INCLUDE VIRTUAL="/_borders17/website-2018-form-validation.html"-->
<%
FormHeader = "Request Demo Now"
FormBtn = "Get Demo Now"
sub Process
Interest = "Demo Request: Website - mrkt"
WebComment = Comments
CSR = UserLog(Interest, "DQT")
Message = Comments & vbCrLf
Message = Message & " Name: " & Name & vbCrLf
Message = Message & " Email: " & email & vbCrLf
Message = Message & " Phone: " & Phone & vbCrLf
Message = Message & " Company: " & Company & vbCrLf
Message = Message & " Product: " & Interest & " " & vbCrLf
Message = Message & " GDPR Agreement: " & Agreement & Checked & gdpragree & vbCrLf
Message = Message & " Referrer: " & REFERER & vbCrLf & vbCrLf
message = message + Ip2Message & vbCrLf & vbCrLf
result = Mail("[email protected]", emailfrom, Interest & " " & Reg & " " & IpCountry & " " & Csr, Message )
end sub
%>
</head>
<body>
<!--#INCLUDE VIRTUAL="/codeanalytics/google-tag-manager-body.htm"-->
<!--#INCLUDE VIRTUAL="/_borders17/nav/2018/nav.html"-->
<main>
<section>
<!-- HTML CONTENT HERE -->
</section>
</main>
<!--#INCLUDE VIRTUAL="/_borders17/footer/2018/footer.html"-->
<!--#INCLUDE VIRTUAL="/_borders17/assets/js-files.html"-->
<script>
setTimeout(function() {
var script = document.createElement('script');
script.type = "text/javascript";
script.setAttribute("id", "6461f488b9172537ed0bfce1966c165e");
script.src = "//support.website.com/script.php?id=6461f488b9172537ed0bfce1966c165e";
console.log(script);
document.querySelector('head').appendChild(script);
}, 5000);
</script>
</body>
</html>
<% sub Form%>
<%end sub%>
JS
setTimeout(function() {
var script = document.createElement('script');
script.type = "text/javascript";
script.setAttribute("id", "6461f488b9172537ed0bfce1966c165e");
script.src = "//support.website.com/script.php?id=6461f488b9172537ed0bfce1966c165e";
console.log(script);
document.querySelector('head').appendChild(script);
}, 5000);

document.getElementsByTagName('head')[0].appendChild(script);. May put aconsole.log(script), before that line?console.log(document.getElementsByTagName('head').length)- if it's0then you don't have a<head>section, which would also give this error. Add a<head>section to your page.