开发者

Javascript get image src: FF shows escaped chars, IE doesn't

If I set:

<img src="test-àè" onclick="alert(this.src);">

on FF the alert shows an escaped message: test-%C3%A0 while on IE it shows the unescaped version: test-àè

开发者_运维问答

I'm using:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

in my page and windows-1252 encoding

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">

Do you know why is this happening?


It's because firefox (and Chrome too) automatically URL encodes your the src because it is assumed to be a URL.

Here's a little test:

<img src="test-àè" foo='test-àè' onclick="alert(this.src);alert(this.getAttribute('foo'));">

In ie you get 'test-àè' 2 times. In Firefox you get 'test-àè' only the second time.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜