window.open alternative?

  • Thread starter Thread starter Dave
  • Start date Start date
D

Dave

I have a button on a nested master.page that opens a popup titled
OnlineHelp.aspx with window.open. It works fine as long as I stay in
the root of my site. When I navigate to a page in another folder it
thinks that the OnlineHelp page is in the root of that folder...and it
gets lost. Below is the code that I'm using...

StringBuilder sb = new StringBuilder();
sb.Append("<script>");
sb.Append("window.open('Documentation/OnlineHelp.aspx',
'','menubar=0,toolbar=0,height=475,width=435,resizable=1,scrollbars=1,
Left=50, top=120');");
sb.Append("</script>");


is there another way to identify the path?

Or is there a more prefered way to do this?

Thanks for your help.
 
Thanks for the quick reply Mark!

In your comment about replacing sb.Append("<script>") with sb.Append
("<script type=\"text/javascript\">"); ....what would be the closing
tag for something like this?

Thanks
 
Dave said:
Thanks for the quick reply Mark!

In your comment about replacing sb.Append("<script>") with sb.Append
("<script type=\"text/javascript\">"); ....what would be the closing
tag for something like this?

</script>
 
Dave said:
I have a button on a nested master.page that opens a popup titled
OnlineHelp.aspx with window.open. It works fine as long as I stay in
the root of my site. When I navigate to a page in another folder it
thinks that the OnlineHelp page is in the root of that folder...and it
gets lost. Below is the code that I'm using...

StringBuilder sb = new StringBuilder();
sb.Append("<script>");
sb.Append("window.open('Documentation/OnlineHelp.aspx',
'','menubar=0,toolbar=0,height=475,width=435,resizable=1,scrollbars=1,
Left=50, top=120');");
sb.Append("</script>");


is there another way to identify the path?

Or is there a more prefered way to do this?

Thanks for your help.

Specify the url from the web root, and use the ResolveUrl method to get
an url that the client can use:

string url = Page.ResolveUrl("~/Documentation/OnlineHelp.aspx");
string code =
"<script type=\"text/javascript\">" +
"window.open('" + url +
"','_blank','menubar=0,toolbar=0,height=475,width=435,resizable=1,scrollbars=1,left=50,
top=120');" +
"</script>");

There isn't really any use for a StringBuilder when concatenating
something simple as this.

Use "_blank" for window name if you want to open a new window. Leaving
it empty may have unpredicted effects.
 
Back
Top