Target='_blank' to show in new window, NOT new tab, possible?

后端 未结 9 1121
逝去的感伤
逝去的感伤 2020-11-27 17:25

How can I do this?

In firefox the link opens in a new tab... I don\'t want users to have to set settings of their browsers for this...

I want a pop-up to app

相关标签:
9条回答
  • 2020-11-27 17:59

    When I was looking into this issue I noticed that the "height" and "width" portions of the window.open() function were what made the link open in a new window instead of a new tab.

    So to open a similarly-sized browser I just passed the window.innerHeight and window.innerWidth to the window.open() function.

    I would have just commented on @M2012's answer, but I don't have enough points yet...

    Hope this helps!

    0 讨论(0)
  • 2020-11-27 17:59

    You cannot control this.

    But you can try to open in a new window and then show an alternative solution if the browser rejects the attempt.

    You can accomplish this by checking the return value of window.open().

    var win = window.open(strUrl, strWindowName);
    if (!win) {
        // Call failed. Handle it here. 
        // You can for example open content in a model or show a button that 
        // will open content in a new tab
    }
    

    window.open documentation: https://developer.mozilla.org/en-US/docs/Web/API/Window/open

    0 讨论(0)
  • If you want to use this thing using Code Behind then it will also work...

    protected void lnkAddNewWorkout_Click(object sender, EventArgs e)
        {
      //  Response.Write("<script>window.open('MyCreatedWorkout.aspx','_blank');</script>");    //it Open in new tab
    
        ResponseHelper.Redirect("MyCreatedWorkout.aspx", "_blank", "menubar=0,width=700,height=700");
    
        }
    
    
    
     public static class ResponseHelper
        {
            public static void Redirect(string url, string target, string windowFeatures)
            {
                HttpContext context = HttpContext.Current;
            if ((String.IsNullOrEmpty(target) ||
                target.Equals("_self", StringComparison.OrdinalIgnoreCase)) &&
                String.IsNullOrEmpty(windowFeatures))
            {
    
                context.Response.Redirect(url);
            }
            else
            {
                Page page = (Page)context.Handler;
                if (page == null)
                {
                    throw new InvalidOperationException(
                        "Cannot redirect to new window outside Page context.");
                }
                url = page.ResolveClientUrl(url);
    
                string script;
                if (!String.IsNullOrEmpty(windowFeatures))
                {
                    script = @"window.open(""{0}"", ""{1}"", ""{2}"");";
                }
                else
                {
                    script = @"window.open(""{0}"", ""{1}"");";
                }
    
                script = String.Format(script, url, target, windowFeatures);
                ScriptManager.RegisterStartupScript(page,
                    typeof(Page),
                    "Redirect",
                    script,
                    true);
            }
        }
    }
    

    Refrenced By: http://www.codeproject.com/Tips/317410/Response-Redirect-into-a-new-window

    0 讨论(0)
  • 2020-11-27 18:05

    This is working fine

    window.open(yoururl, "Popup", "location,status,scrollbars,resizable,width=800, height=800");
    

    For all parameters see window.open

    0 讨论(0)
  • 2020-11-27 18:07

    You cannot control this - it's entirely at the discretion of the user-agent; which is the point, after all. All you can specify is that the page be opened in a different viewpane context, and it's up to the user to decide how they want your window to take up their screen space/taskbar list/Alt-Tab shortcuts etc.

    In fact I'd go even further and say that if at all possible you should avoid opening up a new tab/window at all. I know that I get a little annoyed when websites do this, and it feels a bit clunky and 1990s what with all the Ajax and floating divs and magic we have nowadays.

    0 讨论(0)
  • 2020-11-27 18:07
    <a href="javascript:window.open('http://example.com/popup.html','blank')">Contact</a>
    
    0 讨论(0)
提交回复
热议问题