如下是自己在做一些开发的时候遇上的问题,想必电脑前的你也遇上了吧,赶紧拿笔记下吧。

遇到了几个在IE7有问题,但在IE6中使用正常的问题,共三个:

1、js关闭窗口时老提示的问题。 2、上传图片时无法预览的问题。 3、window.status 无效的问题。

关于第一个,以前在IE6下关闭窗口是这样的,window.opener = null;window.close();在IE7中,这样是不行的,仍然会弹出提示,必须在中间加一句,window.open("","_self"); 像下面的形式就行了。 window.opener = null; window.open("","_self");//这是IE7中必需的 window.close();

二、上传图片时的预览 在IE6中可以这样,非常方便。

<input type="file" onchange="Preview(this)"/> <img id="imgPreview" /> <script type="text/javascript"> function Preview(file){ document.getElementById("imgPreview").src = this.value; } </script>

但是在IE7中,这样无效,那天我这样测试的时候我用的是 GreenBrowser(绿色浏览器),发现竞然也能预览,但在 MS IE7中就不行,我就纳闷了,我去看了百度相册,他的上传相片预览也是使用这种方式,我是用绿色浏览器看百度相册,用MSIE看我的程序,百度相册上传时能预览,我的程序就是不行.结果我一直在怀疑是不是程序哪里搞错了,上网查了好多资料.硬是没搞定,后来我用MS IE 进百度相册,才发现,原来百度相册也不能预览了.原来是绿色浏览器惹的祸,怪吧,这可是个IE内核的浏览器哦,以后大家记住,测试程序时一定要用微软的IE7,用其它IE内核的浏览器可能会有意想来到的问题. 那在IE7下怎么实现预览呢?答案是:用滤镜,请看下面: 请选择要上传的相片:<input type="file" onchange="Preview(this);" /><br /> <div id="imgPreview" style="filter:progid:DXImageTransform.Microsoft. AlphaImageLoader(sizingMethod=scale);width:400px;height:200px;"></div> function Preview(imgFile) { document.getElementById("imgPreview").filters. item("DXImageTransform.Microsoft.AlphaImageLoader").src = imgFile.value; }

关于AlphaImageLoader滤镜,我顺便也转过来。

语法: filter: progid: DXImageTransform.Microsoft.AlphaImageLoader( enabled=bEnabled, sizingMethod=sSize, src=sURL) 属性: enabled : 可选项。布尔值(Boolean)。设置或检索滤镜是否激活。true | false       true : 默认值。滤镜激活。      false : 滤镜被禁止。

sizingMethod : 可选项。字符串(String)。设置或检索滤镜作用的对象的图片在对象容器边界内的显示方式。 crop : 剪切图片以适应对象尺寸。        image : 默认值。增大或减小对象的尺寸边界以适应图片的尺寸。        scale : 缩放图片以适应对象的尺寸边界。PS:自己的体会是,如果padding 和margin的大小不适中的的话,那么背景图片会被撑大。这个缩放还是挺好用的,就相当于那个background-repeat。       

src : 必选项。字符串(String)。使用绝对或相对 url 地址指定背景图像。假如忽略此参数,滤镜将不会作用。

说明:在对象容器边界内,在对象的背景和内容之间显示一张图片,并提供对此图片的剪切和改变尺寸的操作。如果载入的是PNG(Portable Network Graphics)格式,则0%-100%的透明度也被提供。 PNG(Portable Network Graphics)格式的图片的透明度不妨碍你选择文本。也就是说,你可以选择显示在PNG(Portable Network Graphics)格式的图片完全透明区域后面的内容。

三、window.status 不显示的问题

在ie6中,使用window.status =" 欢迎光临我的博客!!!",就能在状态栏显示这么一行字,但在IE7中,本机测试的时候很正常,能显示,但传的服务器上去以后就是不显示,程序运行也没有错误,开始我怀疑是服务器的安全设定问题,后来才发现,又是IE7的问题,IE7的安全性设置中,默认是不能许脚本更新状态栏的。真是可惜了,又少了一块可利用的区域。如果是自己的电脑的话,可以自己更改设置,使IE7也能显示。方法是:工具--》Internet 选项--》安全 -- 选中Internet后 点 自定义级别 --》找到“允许状态栏通过脚本更新”,将默认的禁用改为启用就行了。我特地截了张图。

以上三个虽然是小问题,但如果不明白是浏览器引起的话,很多朋友估计会花很多时间调试程序,但程序是没有问题的。所以我把它们写在这,希望对大家有所帮助。

关于收藏

IE6、IE7 的"加入收藏"代码: window.external.addFavorite(sURL, sTitle); 两点说明:addFavorite 的第一个字母 a 不是大写!

Firefox 的"加入收藏"代码:方法一、<a href="http://www.webyoung.cn/" title="w" rel="sidebar">加入收藏</a> 关键在于 rel="sidebar";方法二、window.sidebar.addPanel(sTitle, sURL, "");第一个参数是收藏名称;

关于自动换行 CSS .wrap{word-wrap:break-word; width:200px;}

JS 实现的幻灯功能 <HTML> <HEAD> <TITLE> New Document </TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT="">

<META NAME="Description" CONTENT=""> </HEAD>

<BODY> <div align="center"><div id=AdRotator></div><input id="second"><button onclick="adRotator.set(getRef('second').value)">set time</button></div> <SCRIPT LANGUAGE="JavaScript">

<!-- function adRotator() {}; adRotator.initialize=function(o) { // script by blueDestiny

this._t = new Array(); this._l = new Array(); this._p = new Array(); this._i = new Image(); this._c = 0; this._f = false; this._o = o;

this._timeout = null; this._html = "";

// configration. // @ image width // @ image height // @ rotator speed // @ filter type

this._w = 450; this._h = 450; this._s = 4; this._x = 23;

return this; }; adRotator.add=function(p,t,l) { with (this) { _p.push(p); _t.push(t); _l.push(l); }};

adRotator.load=function() { with (adRotator) { if( _i.readyState=='complete' ) { if(_p.length-1==_c) { _f = true; _c = 0; window.clearTimeout(_timeout); //getRef("AdRotator").innerHTML="complete"; adRotator.play(); } else { _c++; getRef(_o).innerHTML="total images " + _p.length + ", loading picture " + _c + ' ' + _i.readyState + "..."; _timeout=window.setTimeout(adRotator.load,10) } } else { getRef(_o).innerHTML="total images " + _p.length + ", loading picture " + _c + ' ' + _i.readyState + "..."; _timeout=window.setTimeout(adRotator.load,10) } }};

adRotator.play=function() { with (adRotator) { if( _f ) { _html = ""; _html += '<table style="border:1px solid #333333;"><tr><td style="font-size:9pt;font-family:tahoma;font-weight:bold;">' _html += '<div id="rotatorPlayer"' + ' style="width:' + _w + '' + ';height:"' + _h + '"' + '>' _html += '<a href="' + ( _l[_c] ? _l[_c] : "javascript:void(0);" ) + '">'; _html += '<img id="rotatorPic" src="' + _p[_c] + '"' + ' width="' + _w + '"' + ' height="' + _h + '"' + (_t[_c]?' title="' + _t[_c] + '"':'') + ' style="border:1px solid blue;FILTER:revealTrans(transition=' + _x + ',duration=1);"' + ' >'; _html += (_t[_c]?('<div align="center">' + (_c+1) + '. ' + _t[_c] + '</div>'):'<p></p>'); _html += '</a>'; _html += "</div>"; _html += '<div align="right">';

for(var i=0; i<_p.length; i++) _html += '<span' + ' style="border:1px solid #333333;padding:1px 5px 1px 5px;height:20px;text-align:center;cursor:' + (_c==i ? ('default;background-color:red;"') : 'hand;" onclick="adRotator.select(' + i + ')"') + '>' + (i>8?(i+1):('0'+(i+1)))+ '</span> ';

_html += "</div></td></tr></table>"; getRef(_o).innerHTML = _html;

getRef("rotatorPic").filters[0].Apply(); getRef("rotatorPic").filters[0].Play();

next(); } else { _i.src = _p[_c]; adRotator.load(); } }}; adRotator.next=function() { with (this) { (_p.length-1==_c) ? _c=0 : _c++; _timeout=window.setTimeout(adRotator.play,_s*1000); }}; adRotator.select=function(i) { with (this) { window.clearTimeout(_timeout); _c=i; adRotator.play(); }}; adRotator.set=function(second) { with (this) { window.clearTimeout(_timeout); if((/\d+/).test(second)==true) { _s=second; adRotator.play(); } else { alert("must be digit!") adRotator.play(); } }}; function getRef(id) { return (document.all?document.all(id):document.getElementById(id)); } adRotator.initialize("AdRotator");

adRotator.add("http://img1.qq.com/ent/20060218/3215110.jpg","aa","http://www.7dspace.com") adRotator.add("http://img1.qq.com/ent/20060218/3215111.jpg") adRotator.add("http://img1.qq.com/ent/20060218/3215112.jpg") adRotator.add("http://img1.qq.com/ent/20060218/3215113.jpg") adRotator.add("http://img1.qq.com/ent/20060218/3215114.jpg")

adRotator.play(); //-->

</SCRIPT> </BODY> </HTML>