简体   繁体   中英

Javascript setting dynamic values for src attribute getting error Cross-Origin Read Blocking (CORB) blocked cross-origin response

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 (ie 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.

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 ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM