在百度贴吧发图片,想给图片加些功能如自己发帖后还能控制真实图片地址。
于是使用php的header做了简单的location重定向。
简单的例子test.php内容如下:
<?php
if ($_GET["ref"]) {
header("HTTP/1.1 301 Moved Permanently");
header("Location: " . $_GET["ref"]);
}
?>
于是可以通过test.php?ref=$imgurl访问一张图片,如
<img src="http://post.theclassic.cn/debug/test.php?ref=http://www.baidu.com/search/img/logo.gif">
是可以成功显示的。
但是百度贴吧为了控制图片大小,使用了一个onload后便会运行的js,截剪后如下
<script src="http://static.tieba.baidu.com/tb/js/pb.js?v=20090811112651"
type="text/javascript"></script>
<img onload="Page.resetChangedSizeImage('old',this);"
src="http://post.theclassic.cn/debug/test.php?ref=http://www.baidu.com/search/img/logo.gif">
这小段代码我放在了
http://post.theclassic.cn/debug/a.html中,大家可以访问查看
出现的问题是用firefox打开后会反复重定向链接
http://post.theclassic.cn/debug/test.php?ref=http://www.baidu.com/search/img/logo.gif和链接
http://www.baidu.com/search/img/logo.gifhttp分别返回为301和304,即永久重定向和未修改。
打开时按按刷新偶尔使得logo真正缓存后就不再继续redirect了,而再刷新又会。。
但不知道是哪里出了问题,只怀疑是firefox的js引擎问题或者对onload的判断,也许百度的代码和我写的也都有问题,旁观者清,所以来请大家帮忙看一下。
而除了我在使用的firefox3.5.2外,还测试了chrome和IE6、IE8,均没有这种问题。
--
修改:Tonn FROM 202.116.64.*
FROM 202.116.64.*