Results 1 to 9 of 9

Thread: Javascript trigger after loading image?

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    14

    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?

  2. #2

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    14

    Re: Javascript trigger after loading image?

    Can't anybody help me with this?

  3. #3
    New Member
    Join Date
    Jan 2006
    Posts
    8

    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

  4. #4

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    14

    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

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Javascript trigger after loading image?

    Place the code for resizing in the body's onload event.

  6. #6

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    14

    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?

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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.

  8. #8

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    14

    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)

  9. #9
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Javascript trigger after loading image?

    Try backtracking.

    Try to get the page to do a simple alert() in javascript. Is that working?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width