1

I wanted to pass dynamic value to src attribute of javascript, I tried couple of options but it didn't work. I am using plain javascript, not jquery.

These are the ways I tried; 1.

<script>
        var script = document.createElement('script');
        script.src ="some url here";
        script.type="text/javascript";
        document.head.appendChild(script); 
   </script>

Error message: Cross-Origin Read Blocking (CORB) blocked cross-origin response https://same url/ with MIME type text/html. See https://www.chromestatus.com/feature/5629709824032768 for more details.

Option 2:

<script>
var fileName = "<%=request.getAttribute("someurl here")%>";
document.write("<script type=\"text/javascript\" src=\"" + fileName + "\"><\/script>");
</script>

Error message: A parser-blocking, cross site (i.e. different eTLD+1) script, https://same url/, is invoked via document.write. The network request for this script MAY be blocked by the browser in this or a future page load due to poor network connectivity. If blocked in this page load, it will be confirmed in a subsequent console message. See https://www.chromestatus.com/feature/5718547946799104 for more details.

App User
  • 15
  • 4
  • Possible duplicate of [A Parser-blocking, cross-origin script is invoked via document.write - how to circumvent it?](https://stackoverflow.com/questions/39610829/a-parser-blocking-cross-origin-script-is-invoked-via-document-write-how-to-ci) – Geuis Mar 25 '19 at 20:38

1 Answers1

0

The server says the URL points to an HTML document.

Since you are trying to execute it as JavaScript, the browser objects and throws an error message.

So either:

  • It really it as HTML document and you probably have the wrong URL or
  • The server is wrong and you need to fix it to set the correct Content-Type response header (application/javascript).
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335