简体   繁体   中英

C# open page in new tab

I have this code:

string urlAccomodation = ar.GetAccommodationHashURL(
    StudentId.ToString(),
    sp.GetSysSetting("accomodationSecret"),
    misc.GetAppSetting("urlAccommodation"));
string returnURL = "&url=" + Server.UrlEncode(
    ar.GetHashURL(
        StudentId.ToString(),
        sp.GetSysSetting("accomodationSecret"),
        "http://applicants.rac.ac.uk/default.aspx"));
string url = "window.open('" + urlAccomodation + returnURL + "_blank')";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Script", url, true);

What I'm trying to do is open a page in a new tab. It works fine for Mozilla and Internet Explorer but Chrome and Safari are opening this in a new window instead of a new tab. Can you please help ? (I do apologize for my English)

Not sure based in the info provided, and might not help anyway, but you might be mis-formatting the string url= line:

string url = "window.open('" + urlAccomodation + returnURL + "_blank')";

Try

string url = "window.open('" + urlAccomodation + returnURL + "','_blank')";

The target should be a separate argument to the window.open method, eg: window.open('some.aspx','_blank')

From what I know this is browser setting and cannot be controlled from code.

I'm guessing it works on FF and IE because of the proper settings in place.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM