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
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!
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
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
This is working fine
window.open(yoururl, "Popup", "location,status,scrollbars,resizable,width=800, height=800");
For all parameters see window.open
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.
<a href="javascript:window.open('http://example.com/popup.html','blank')">Contact</a>