Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xlink:href filename#id renders as #id only #36

Open
hernan-almeida opened this issue May 26, 2017 · 3 comments
Open

xlink:href filename#id renders as #id only #36

hernan-almeida opened this issue May 26, 2017 · 3 comments

Comments

@hernan-almeida
Copy link

hernan-almeida commented May 26, 2017

In IE 11, when using svgxuse.js I noticed that my xlink:href value in the source code is not the same as what renders in the DOM.

<div class="glyph fs1">
    <svg class="icon icon-palette"><use xlink:href="symbol-defs.svg#icon-palette"></use></svg>
</div>

turns out like this:

<div class="glyph fs1">
    <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-paper-plane">
        <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#icon-paper-plane" />
    </svg>
</div>

This is a problem if you are switching svg files dynamically. Without the full path, IE keep referencing the previous file. I run into this problem because we have icon sprite sheets for multiple sizes and #id points to multiple matches as I switch around sprite sheets.

I have:

icons.svg
/24/icons.svg
/48/icons.svg

All of them have the same set of icons (same id's) but the larger icons have more detail. if I swap the url in the xlink:href using JavaScript, I end up rendering the wrong svg because svgxuse.js trims everything but the #.

@StK88
Copy link

StK88 commented Jun 20, 2017

+1

@simianarmy
Copy link

Was this fixed? The author of the PR above seems to have given up

@gempir
Copy link

gempir commented Aug 20, 2020

This isn't inherently a bug this is how the library operates. It replaces the href because the svg is attached to the current body so it only needs the #id to reference it.

If you want to dynamically switch you will have to insert the whole path again. And then if it fails to load in IE11 the library will attach the new svg to the body again and change the href to only an #id again.

Not sure how good the last part works of it watching for the change of a href.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants