简体   繁体   English

无法使用w3school HTML包含

[英]Can't use w3school HTML include

So here's the link to the original w3school article about HTML include using their .js file link . 因此,这里是原始w3school关于HTML的文章的链接,包括使用他们的.js文件链接
I literally copied everything from the w3school example, but got this error : 我从w3school示例中确实复制了所有内容,但收到此错误:

w3school.js:131 XMLHttpRequest cannot load file:///C:/Users/KBS-3/Desktop/project_1/html/header.html. w3school.js:131 XMLHttpRequest无法加载文件:/// 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. 跨源请求仅支持以下协议方案:http,数据,chrome,chrome扩展名,https,chrome-extension-resource。

Here's my index.html 这是我的index.html

 <!DOCTYPE html> <html> <script src="http://www.w3schools.com/lib/w3data.js"></script> <body> <div w3-include-html="content.html"></div> <script> w3IncludeHTML(); </script> </body> </html> 

and content.html 和content.html

 <h1>HELLO WORLD</h1> 

Any ideas to resolve this ? 有解决这个问题的想法吗?

As the error suggests, you are trying to include a local html file file:///C:/Users/KBS-3/Desktop/project_1/html/header.html. 如错误所示,您尝试包含一个本地html文件file:///C:/Users/KBS-3/Desktop/project_1/html/header.html. using javascript which is not permitted due to security reasons. 由于安全原因,不允许使用javascript。 (Imagine, if it were allowed, websites could read any of your local hard drive data). (想象一下,如果允许的话,网站可以读取您本地的任何硬盘数据)。

Solution: Move your website to localhost ie use XAMP or a real server and you'll be fine. 解决方案:将您的网站移至localhost即使用XAMP或真实的服务器,就可以了。

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

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