LiLo Posted April 11, 2006 Posted April 11, 2006 Hi, :D How to execute a javascript function when the asp.net webpage is first loaded? or refreshed? Currently, I put the javascript function in the Page_Load Method. Visual Studio 2005 is used. The asp.net language is in vb. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Page.RegisterStartupScript("MyScript", _ "<script language = 'javascript'>" & _ "function showIFrame(){" & _ "var iframe = document.createElement('iframe');" & _ "iframe.ID = 'testiframe';" & _ "iframe.name = 'testiframe';" & _ "iframe.frameborder = 1;" & _ "iframe.style.top = 200;" & _ "iframe.width = 175;" & _ "iframe.scrolling = 'auto';" & _ "iframe.src = 'C:\Test.html';" & _ "window.document.body.appendChild(iframe);" & _ "return false;" & _ "}" & _ "</script>") Button1.Attributes("onClick") = "return showIFrame()" End Sub The jscript above can correctly display an IFrame when the button is clicked. But how to make the javascript execute by itself when the webpage loads? Quote
fizzled Posted April 11, 2006 Posted April 11, 2006 Try the OnLoad() event Try using the OnLoad event in the body tag of your html. <body OnLoad="showIFrame()"> Quote
LiLo Posted April 12, 2006 Author Posted April 12, 2006 Hi, Thank you for the reply. I used the window.onload javascript method and it can work too :) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.