无法将外部源加载到SVG的<use>标记

时间:2015-05-15 03:12:32

标签: html google-chrome svg

我收到一个错误,我真的不知道如何处理它。这是错误:[来自Cr]

Unsafe attempt to load URL file:///C:/Users/Ho%20Thi%20Kim%20Loan/Desktop/BeTe/assets/file-text2.svg#icon-file-text2 from frame with URL file:///C:/Users/Ho%20Thi%20Kim%20Loan/Desktop/BeTe/index.html. Domains, protocols and ports must match.

我的代码看起来就像CSS-Trick

<svg viewBox="0 0 100 100">
   <use xlink:href="assets/file-text2.svg#icon-file-text2"></use>
</svg>

我的SVG:

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
    <symbol id="icon-file-text2" viewBox="0 0 1024 1024">
        <title>file-text2</title>
        <path class="path1" d="M917.806 229.076c-22.212-30.292-53.174-65.7-87.178-99.704s-69.412-64.964-99.704-87.178c-51.574-37.82-76.592-42.194-90.924-42.194h-496c-44.112 0-80 35.888-80 80v864c0 44.112 35.888 80 80 80h736c44.112 0 80-35.888 80-80v-624c0-14.332-4.372-39.35-42.194-90.924zM785.374 174.626c30.7 30.7 54.8 58.398 72.58 81.374h-153.954v-153.946c22.984 17.78 50.678 41.878 81.374 72.572zM896 944c0 8.672-7.328 16-16 16h-736c-8.672 0-16-7.328-16-16v-864c0-8.672 7.328-16 16-16 0 0 495.956-0.002 496 0v224c0 17.672 14.326 32 32 32h224v624z"></path>
        <path class="path2" d="M736 832h-448c-17.672 0-32-14.326-32-32s14.328-32 32-32h448c17.674 0 32 14.326 32 32s-14.326 32-32 32z"></path>
        <path class="path3" d="M736 704h-448c-17.672 0-32-14.326-32-32s14.328-32 32-32h448c17.674 0 32 14.326 32 32s-14.326 32-32 32z"></path>
        <path class="path4" d="M736 576h-448c-17.672 0-32-14.326-32-32s14.328-32 32-32h448c17.674 0 32 14.326 32 32s-14.326 32-32 32z"></path>
    </symbol>
</defs>

SVG图像鞋面属于IcoMoon

现在我真的想知道如何处理这个错误。我的所有协议和端口都匹配,这是localhost。它到底怎么会有域名? (你不认为这是一个错误吗?)

1 个答案:

答案 0 :(得分:0)

根据@Julien评论,这不会在本地运行(不适用于Chrome,Opera或IE,但在Firefox上运行正常),因此您需要在服务器上完成此操作。

另外我想通了,在我的情况下(如在你的情况下),也是从我的外部<defs></defs>文件中删除svg元素的问题,因为它阻止了其内容的显示。

所以继续把它擦掉,一切都按预期工作。