html include 无效,不能使用w3school HTML include

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或一个真正的服务器,你就会没事。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值