vbFace Posted January 12, 2004 Posted January 12, 2004 Is there a way (I guess through JavaScript? or ASP.NET) to redirect a user to their own home page that is set in their browser, like when they click the Home icon on their toolbar? Quote
vbFace Posted January 12, 2004 Author Posted January 12, 2004 I found a solution. I'll post it for the benefit of anyone searching these forums: <% Response.write("<script language=" & Chr(34) & "JavaScript" & Chr(34) & ">" & Chr(13)) Response.write("<!--" & Chr(13) & "if (document.layers) {" & Chr(13)) Response.write(" window.home();" & Chr(13) & "} else {" & Chr(13)) Response.write(" window.location.href=" & Chr(34) & "about:home" & Chr(34) & ";" & Chr(13)) Response.write("}" & Chr(13) & "//-->" & Chr(13) & "</script>" & Chr(13)) %> Quote
samsmithnz Posted January 12, 2004 Posted January 12, 2004 But out of all that code, its the window.home that does the actual redirection. Quote Thanks Sam http://www.samsmith.co.nz
vbFace Posted January 13, 2004 Author Posted January 13, 2004 No, window.home() only works in Netscape browsers. The Else statement takes care of IE. Quote
samsmithnz Posted January 13, 2004 Posted January 13, 2004 So whats with all the response.write stuff? Why don't you just use the client side script in the html? Quote Thanks Sam http://www.samsmith.co.nz
vbFace Posted January 13, 2004 Author Posted January 13, 2004 Because I really don't know what I am doing yet! :) Also, I thought that ASP.NET won't handle straight JavaScript when it serves up the resulting ASP.NET page in HTML format, so it must be written with Response.Write. Am I wrong? Quote
samsmithnz Posted January 13, 2004 Posted January 13, 2004 Oh I see. The response.write will work, but it would definetly look cleaner if you just added this code to the body of your html. You see this is Client side Javascript, so ASP.NET doesn't even really process it, the browser does. All the response.write is add it to the HTML stream so that the browser gets it. If you view the source you'll see it sitting there (and it should look the same as what I below unless I made a typo) <script language="JavaScript"> if (document.layers) { window.home(); } else { window.location.href="about :home"; } </script> Quote Thanks Sam http://www.samsmith.co.nz
vbFace Posted January 13, 2004 Author Posted January 13, 2004 Oh, cool. I guess only if I need to write to the HTML stream from a VB/C# code section, then I need Response.Write. That is nice to know! 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.