开发者

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

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 appear with contact-form whenever user clicks 'contact' on my开发者_开发百科 main page.

How should I do this?


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.


This is working fine

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

For all parameters see window.open

Edited Date:- 12th Aug, 2021 If you does not want to use JavaScript Function, then You can write Inline Script for Open Page in New Windows, & it is support all the modern browsers

<a href="https://stackoverflow.com/" onclick="window.open('https://stackoverflow.com/', 'newwindow', 'width=400, height=250'); return false;">with href</a>


<a href="#" onclick="window.open('https://stackoverflow.com/', 'newwindow', 'width=400, height=250'); return false;">without href</a>

You can see Live Working example on this jsfiddle.net link


<a href="javascript:window.open('http://example.com/popup.html','blank')">Contact</a>


I believe this is a browser-only setting that cannot be set from HTML or Javascript.


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!


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


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


Best way to to open a new window in HTML.

<a href="#" onclick="MM_openBrWindow('http://www.google.com','','resizable=yes,width=800,height=600')"> Google</a>

<script>
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
</script>


This is also easy way but link is not visible it is appropriate for button action

<a onclick="window.open('print.html', 'newwindow', 'width=300,height=250');"> Print</a>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜