Javascript trigger after loading image?
I'm having problems with this source code.
I am loading a image from a SQL server. When the image is loaded, the window (opener window -> little) should be the size of the image. I want to trigger a javascript script after the asp.Net code. How do I do this:
Code:
If type = 1 then
image1.imageUrl = lookforimage(imageNr)
I WANT TO TRIGGER THE JAVASCRIPT HERE ? BUT HOW?
Re: Javascript trigger after loading image?
Can't anybody help me with this?
Re: Javascript trigger after loading image?
from your code behind?
like this work for me:
Code:
string popupScript = "<script language='javascript'>" +
"var x=screen.width;" +
"var y=screen.height;" +
"x=x-80;" +
"y=y-100;" +
"window.open('http://www.google.com', 'CustomPopUp', " +
"'Height=' + y + ',Width=' + x +', resizable=no,scrollbars=yes,titlebar=no,status=1,toolbar=no,Left=0,top=0')" +
"</script>";
Response.Write(popupScript);
so it's just a javascript string, and you do a response.write
Re: Javascript trigger after loading image?
Thanx for responding VanPetrol,
But this code just add's a function in the window. I want to trigger it so the window is resized 'after' the image is loaded. I put the code below:
image1.ImageUrl = lookfortheimage(imageNr)
Dim sb as String
sb = "<scr" + "ipt language=javascript>"
sb+= "function window_res() { "
sb+= "var imgW = window.Form1.image1.witdh; "
sb+= "var imgH = window.Form1.image1.height; "
sb+= "window.self.parent.resizeTo(100, 200); "
sb+= "}</scr" + "ipt>"
Response.Write(sb)
When I do this the window will not resize :S
Re: Javascript trigger after loading image?
Place the code for resizing in the body's onload event.
Re: Javascript trigger after loading image?
Dear mendhak,
I did this with body onload event, but when the page is visible it is busy with loading a image from the sql server. With the body onload event it sometimes can't find the width of the image because it loads from the db. Then the javascript comes with undifined witdh wich means the image was not loaded. That's the reason that the trigger must done after the image is loaded. Any suggestions?
Re: Javascript trigger after loading image?
Don't use Response.Write(sb)
Use Page.RegisterClientScriptBlock for your sb, then call it by using Page.RegisterStartupScript to call the function.
Re: Javascript trigger after loading image?
mendak,
When I use your sugg. about the scripting the @#!)(@*# javascript still doesn't trigger. I use the folowing script, why doesn't it still trigger?
Code:
Dim sb as String
sb = "<script language='javascript'>function window_res() { window.self.parent.resizeTo(100, 200); }</scrip " & "t>"
image1.ImageUrl = GoAndFindTheImageFromSQL(imageNr)
Page.RegisterClientScriptBlock("script", sb)
Page.RegisterStartupScript("script", sb)
Re: Javascript trigger after loading image?
Try backtracking.
Try to get the page to do a simple alert() in javascript. Is that working?