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关于HTML的文章的链接,包括使用他们的。js文件链接。我照搬了w3school的例子,但是有一个错误:
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.
w3school。131 XMLHttpRequest不能加载文件:///C:/Users/KBS-3/Desktop/project_1/html/header.html。跨源请求只支持协议方案:http、数据、chrome、chromeextension、https、chromeextension -resource。
Here's my index.html
这是我的index . html
w3IncludeHTML();
and content.html
和content.html
HELLO WORLD
Any ideas to resolve this ?
有办法解决这个问题吗?
1 个解决方案
#1
3
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).
如错误所示,您正在尝试包含一个本地html文件:///C:/Users/KBS-3/Desktop/project_1/html/header.html。由于安全原因不允许使用javascript。(想象一下,如果允许的话,网站可以读取任何本地硬盘数据)。
Solution: Move your website to localhost i.e. use XAMP or a real server and you'll be fine.
解决方案:将你的网站移到本地主机,例如使用XAMP或一个真正的服务器,你就会没事。