window.open alternative?

Discussion in 'ASP .Net' started by Dave, Feb 14, 2009.

  1. Dave

    Dave Guest

    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.
     
    Dave, Feb 14, 2009
    #1
    1. Advertising

  2. Dave

    Dave Guest

    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




    On Feb 14, 11:39 am, "Mark Rae [MVP]" <> wrote:
    > "Dave" <> wrote in message
    >
    > news:...
    >
    > >        sb.Append("<script>");

    >
    > The various methods of the ClientScript class are the preferred way to
    > inject JavaScript into aspx pages.
    >
    > If you absolutely must use the method that you're currently using, at least
    > change the above line to:
    > sb.Append("<script type=\"text/javascript\">");
    >
    > > Is there another way to identify the path?

    >
    > So long as all your subfolders are at the same level, you could use:
    > window.open('../Documentation/OnlineHelp.aspx',
    >
    > > Or is there a more prefered way to do this?

    >
    > Depends who you talk to, I suppose. I'd almost certainly use an AJAX modal
    > popup:http://www.asp.net/ajax/ajaxcontroltoolkit/samples/modalpopup/modalpo...
    >
    > --
    > Mark Rae
    > ASP.NET MVPhttp://www.markrae.net
     
    Dave, Feb 14, 2009
    #2
    1. Advertising

  3. Dave wrote:
    > 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>

    --
    Göran Andersson
    _____
    http://www.guffa.com
     
    Göran Andersson, Feb 14, 2009
    #3
  4. Dave wrote:
    > 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.

    --
    Göran Andersson
    _____
    http://www.guffa.com
     
    Göran Andersson, Feb 14, 2009
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ml
    Replies:
    0
    Views:
    1,493
  2. ml
    Replies:
    2
    Views:
    4,899
    John C. Bollinger
    Nov 30, 2004
  3. wax
    Replies:
    9
    Views:
    366
  4. Clare Hsiao
    Replies:
    11
    Views:
    273
    Michael Winter
    Feb 13, 2004
  5. PC HUA
    Replies:
    2
    Views:
    469
    PC HUA
    May 19, 2004
Loading...

Share This Page