how to refresh the page?

A

asnowfall

<img src=...Onlick = "if (!(this.temp>=640)) { this.temp=640; } if
(this.width>=640) { xyz=this.width; this.width=this.temp;
this.temp=xyz; }">

Inline script....
I got the above code from internet and it is used to change the width
of the IMG element. This not only "changes" the width but also
"refreshes" the page so that I can see the change in width.

Function script...
I moved above inline script to a JS file and it is as follows. Now,
'width' of the IMG element seem to change but display does not get
refreshed; and if I add a window.alert( ); then I see screen
refreshing

function Show()
{
iImageWidth = 640;
if(document.getElementById) //gecko(NN6) + IE 5+
{
var obj = document.getElementById("IndividualImageID");
if (!(obj.LastWidth>=iImageWidth))
{
'window.alert( 'obj.LastWidth = ' + obj.LastWidth ); //Uncommenting
this line would
//
display image with new width
obj.LastWidth=iImageWidth;
}
if (obj.width>=iImageWidth)
{
'window.alert( 'obj.LastWidth1 = ' + obj.LastWidth ); //Uncommenting
this line would
//
display image with new width

xyz=obj.width;
obj.width=obj.LastWidth;
obj.LastWidth=xyz;
}
}
}

Please let me know how can I make this script refresh.



Thanks
Ramesh
 
E

Erwin Moller

<img src=...Onlick = "if (!(this.temp>=640)) { this.temp=640; } if
(this.width>=640) { xyz=this.width; this.width=this.temp;
this.temp=xyz; }">

Hi,

The above code is strange:
onLick event?
Does that handler fire when a client licks that image?

Anyway, assuming onClick(): The above code stores the width of the image in
a freshly made property named temp.
If not set, it defaults to 640. If clicked again it switches back to
original format.
Inline script....
I got the above code from internet and it is used to change the width
of the IMG element. This not only "changes" the width but also
"refreshes" the page so that I can see the change in width.

As far as I can see, no refreshing is done. At least not in the above code.
And refreshing the page would certainly result in a new page and thus in
loosing the property named temp for that image.
Same goes for every variable in JavaScript. They are all lost if the page is
refreshed unless you take special precautions, like storing things in
COOKIE or encoding stuff in GET, like:

location='mypage.html?temp=640';

So refreshing is a bad idea, at least in the situation you described.

Regards,
Erwin Moller
 
J

Jim

I'm not sure what your problem in your code is. I just built and ran
the following:

--play.htm--

<html><head>
<script src='play.js' language="JavaScript" type="text/javascript" ></
script>
</head><body>
<img src='winter.jpg' onclick='swapsize(this);' ></img>
</body></html>

--play.js--

function swapsize(el)
{
if (el.width==800) {
el.width=400;
el.height=300;
}
else {
el.width=800;
el.height=600;
}
}

Yes, it's simple. Point is, there is no 'refresh', no round trip to
the server. All that happens is the image changes sizes.

That is what you were looking for, right?

J
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top