简体   繁体   English

Index.html 脚本标记值在运行时被替换

[英]Index.html Script Tag Values Replaced On Run

I'm having an issue with CORS and web page:我遇到了 CORS 和 web 页面的问题:

  • Web page value is changed before page loads Web 页面值在页面加载之前更改
    • But isn't happening with any other pages但没有发生在任何其他页面上
  • I cannot load the homepage properly with jQuery我无法使用 jQuery 正确加载主页
    • But all other pages with the same script load fine但是具有相同脚本的所有其他页面都可以正常加载
  • Doesn't work on Chrome不适用于 Chrome
    • But works locally and on Firefox但在本地和 Firefox 上工作
  • Changed S3 CORS configuration permissions, but hasn't fixed the problem更改了 S3 CORS 配置权限,但尚未解决问题
    • AWS S3 Bucket > Permissions > CORS configuration AWS S3 存储桶 > 权限 > CORS 配置
<!DOCTYPE html>
<html lang="en">
    <head>
        <script
            type="text/javascript" crossorigin="anonymous">$(function () { $.get("assets/head.html", function (data) { $("head").prepend(data); }); });</script>
    </head> 

    <body class="container">
    </body>
</html>

Turns to:转为:

<!DOCTYPE html>
<html lang="en">
    <head>
        <script
            type="text/javascript" crossorigin="anonymous">$(function () { $.get("https://s3-example.amazonaws.com/aws-codestar-example/public/assets/head.html", function (data) { $("head").prepend(data); }); });</script>
    </head> 
    <body class="container">
    </body>
</html>

The error is:错误是:

Access to XMLHttpRequest at 'https://s3-example.amazonaws.com/aws-codestar-example/public/assets/head.html' from origin 'http://example2.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Why is the source changing before read by Chrome?为什么在 Chrome 读取之前源会发生变化?

Write the script in another page & link it in the bottom head or body tag.在另一个页面中编写脚本并将其链接到底部的头部或正文标记中。 As like:就像:

<script src="Right the link page" type="text/javascript">
function...
</script>
</body>

Or:或者:

<script type="text/javascript" src="Right the link page">
  function...
</script>
</head>

Write the script language in the head tag and try or in the bottom body tag.将脚本语言写在head标签和 try 或底部 body 标签中。 As like:就像:

<script type="text/javascript">function...
</script>`
</body>

Or或者

<script type="text/javascript"></script>`
</head>

Than isn't than please remove your browser history, & close all tab than right the URL in the browser tab & run.请删除您的浏览器历史记录,并关闭所有选项卡,然后在浏览器选项卡中关闭 URL 并运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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