admin管理员组文章数量:1405364
So here's the link to the original w3school article about HTML include using their .js file link.
I literally copied everything from the w3school example, but got this error :
w3school.js:131 XMLHttpRequest cannot load file:///C:/Users/KBS-3/Desktop/project_1/html/header.html. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.
Here's my index.html
<!DOCTYPE html>
<html>
<script src=".js"></script>
<body>
<div w3-include-html="content.html"></div>
<script>
w3IncludeHTML();
</script>
</body>
</html>
So here's the link to the original w3school article about HTML include using their .js file link.
I literally copied everything from the w3school example, but got this error :
w3school.js:131 XMLHttpRequest cannot load file:///C:/Users/KBS-3/Desktop/project_1/html/header.html. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.
Here's my index.html
<!DOCTYPE html>
<html>
<script src="http://www.w3schools./lib/w3data.js"></script>
<body>
<div w3-include-html="content.html"></div>
<script>
w3IncludeHTML();
</script>
</body>
</html>
and content.html
<h1>HELLO WORLD</h1>
Any ideas to resolve this ?
Share Improve this question edited Jun 22, 2016 at 6:29 Frits 7,62410 gold badges47 silver badges65 bronze badges asked Jun 22, 2016 at 6:11 RickyRicky 192 silver badges10 bronze badges 1- nah, i tried to copy the content of their js to my local file, not working tho – Ricky Commented Jun 22, 2016 at 6:29
1 Answer
Reset to default 5As the error suggests, you are trying to include a local html file file:///C:/Users/KBS-3/Desktop/project_1/html/header.html.
using javascript which is not permitted due to security reasons. (Imagine, if it were allowed, websites could read any of your local hard drive data).
Solution: Move your website to localhost
i.e. use XAMP
or a real server and you'll be fine.
本文标签: javascriptCan39t use w3school HTML includeStack Overflow
版权声明:本文标题:javascript - Can't use w3school HTML include - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744278112a2598514.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论