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
Add a ment  | 

1 Answer 1

Reset to default 5

As 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