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

图片 URL 分隔符是反斜杠造成背景图片无法加载 #1

Closed
ufologist opened this issue Oct 23, 2015 · 1 comment
Closed

Comments

@ufologist
Copy link
Contributor

在 Window 系统中生成的图片 URL 分隔符是反斜杠().
backgroud-image-wrong-url

background:url(images\107957.png) no-repeat;

这会造成无法加载背景图片, img 中包含的 URL 也一样有反斜杠, 但浏览器似乎有容错机制.

<img class="layer" src="images\c334bf.png" style="left:48px;top:53px;" width="104" height="106">

分析代码 URL 错误是由于使用了兼容系统的路径拼接造成的

image = path.join(images, flag.slice(1, 7) + '.png');

Linux 和 Window 分别采用了不同的路径分隔符(正斜杠和反斜杠), 因此会生成的不同的 URL.

d:\window\b\c

root/linux/b/c

为了避免跨平台问题, 还是直接拼接 URL 好了

image = images + '/' + flag.slice(1, 7) + '.png';

修改代码后的效果, URL 正常了
backgroud-image-correct-url

@zswang zswang closed this as completed in 9fc8f1c Oct 23, 2015
zswang added a commit that referenced this issue Oct 23, 2015
@zswang
Copy link
Owner

zswang commented Oct 23, 2015

感谢反馈和修正

zswang added a commit that referenced this issue Oct 23, 2015
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

2 participants