Javascript,Mozzilla和img.src [英] Javascript, Mozzilla, and img.src

查看:68
本文介绍了Javascript,Mozzilla和img.src的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是'我的代码基本上打开一个弹出窗口,其中有一个

图像并调整大小以适应它。它适用于IE浏览器,但不适用于

Mozilla(没有图片显示,也没有调整大小)。用window.open打开

(''pic.html?''+ path,...);有任何想法吗??谢谢

预付款!

< body bgcolor ="#000000"文本= QUOT;#FFFFFF" onLoad =" loader()"

onBlur =" self.close()" topmargin = 0 leftmargin = 0 marginheight = 0

marginwidth = 0>


< script language =" JavaScript"><! -

函数loader(){

var str = document.location.toString();

var pic = str.substring(str.indexOf( ''?'')+ 1,str.length);


image.src = pic;

image.alt =''图片:'' + pic;

}


函数resizer(){

window.resizeTo(document.all.image.width + 10 ,

document.all.image.height + 30);

window.focus();

}

- >< / script>


< img name =" image" SRC ="" ALT ="" onLoad =" resizer()"

style =" display:block">


< / body>

< / html>

Hi, here''s my code to basically make an popup window open with an
image in it and resize to fit it properly. It works in IE, but not in
Mozilla (no picture shows up and it doesn''t resize). It would be
opened with window.open(''pic.html?''+path,...); Any ideas?? Thanks in
advance!
<body bgcolor="#000000" text="#ffffff" onLoad="loader()"
onBlur="self.close()" topmargin=0 leftmargin=0 marginheight=0
marginwidth=0>

<script language="JavaScript"><!--
function loader() {
var str = document.location.toString();
var pic = str.substring(str.indexOf(''?'')+1, str.length);

image.src = pic;
image.alt = ''Picture: '' + pic;
}

function resizer() {
window.resizeTo(document.all.image.width+10,
document.all.image.height+30);
window.focus();
}
--></script>

<img name="image" src="" alt="" onLoad="resizer()"
style="display:block">

</body>
</html>

推荐答案

嘿,
window.resizeTo(document.all。 image.width + 10,
document.all.image.height + 30);
window.focus();
window.resizeTo(document.all.image.width+10,
document.all.image.height+30);
window.focus();




Don'' t使用all对象,仅限IE。相反,给图片一个ID,

,如ID =''image'',并使用document.getElementById(''image'')来检索

对象。 br />

myImage = document.getElementById(''image'');


window.resizeTo(myImage.width + 10,myImage.height + 30);


请注意,在IE中,如果你使用ID =''somename'',那么你就不能使用

somename作为另一个变量,所以


image = document.getElementById(''image'');


可能在IE中出错。


剩下的应该可以工作了。


祝你好运



Don''t use the all object, its IE only. Instead, give the picture an ID,
like ID=''image'' and use document.getElementById(''image'') to retrieve the
object.

myImage = document.getElementById(''image'');

window.resizeTo(myImage.width+10, myImage.height+30);

Please note that in IE, if you use ID=''somename'', then you can not use
somename as another variable, so

image = document.getElementById(''image'');

might go wrong in IE.

The rest should pretty much work.

Good luck


为什么不呢使用这样的东西 - 对我有用...


< script>

函数resizeMe(){

if( navigator.appName ==''Netscape''){

adjWidth = document.images [0] .width + 0;

adjHeight = document.images [0]。高度+ 30;

}否则{

adjWidth = document.images [0] .width + 0;

adjHeight = document.images [0]。高+ 30;

}


window.resizeTo(adjWidth,adjHeight);

window.focus();

}

< / script>


然后在体内:

< body onload =" resizeMe();" >


有什么好处吗?
why not use something like this - works for me...

<script>
function resizeMe(){
if (navigator.appName == ''Netscape''){
adjWidth = document.images[0].width + 0;
adjHeight = document.images[0].height + 30;
} else {
adjWidth = document.images[0].width + 0;
adjHeight = document.images[0].height + 30;
}

window.resizeTo(adjWidth, adjHeight);
window.focus();
}
</script>

Then in the body:
<body onload="resizeMe();" >

any good?


cp ********* @ wi.rr.com (罗伯特)在留言中写道:< 1a ************ **************@posting.google。 com> ...
cp*********@wi.rr.com (Robert) wrote in message news:<1a**************************@posting.google. com>...
这是我的代码,基本上打开一个弹出窗口,其中有一个
图像并调整大小以适应它。它适用于IE,但不适用于Mozilla(没有图片显示,也没有调整大小)。它会用window.open(''pic.html?''+ path,...)打开。有任何想法吗??谢谢
提前!
Hi, here''s my code to basically make an popup window open with an
image in it and resize to fit it properly. It works in IE, but not in
Mozilla (no picture shows up and it doesn''t resize). It would be
opened with window.open(''pic.html?''+path,...); Any ideas?? Thanks in
advance!




您使用的是仅适用于资源管理器的document.all,您应该使用

docuemtn.getElementById访问元素。



You are using document.all that only works in explorer, you should use
docuemtn.getElementById to access elements.


这篇关于Javascript,Mozzilla和img.src的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆