Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i did a lot of researches and methods, none of them is perfect, but at least the code below almost meet my goal, i need the browser to open the new tab by using code behind.
C#
Response.Write("<script>window.open('http://www.google.com');</script>");

code above open new tab in IE and FF, but it open new windows if user using google chrome.
what should i do to make the google to open the new tab as well?
Posted

Unfortunately you can't.

In IE this is the default action and in FireFox this is a setting that the user can change. However in Chrome this is not anything the user has control over, so it does what the spec says and opens a new window.
 
Share this answer
 
Comments
melvintcs 5-Sep-13 22:02pm    
so if there nothing i can change in Chrome's setting so that it will open the new tab? this is sad :(
Ron Beyer 5-Sep-13 22:07pm    
No, Chrome has some pretty minimalist settings, I've searched for anything that can be changed and there just isn't one there. There are some extensions that may do it, but I wouldn't count on users installing them.
melvintcs 6-Sep-13 0:02am    
may i know what is the name of the extensions?
Ron Beyer 6-Sep-13 0:15am    
I honestly don't know, its just what I read online that there may be some extensions out there, you'll have to search the chrome extensions store and see.
melvintcs 6-Sep-13 1:22am    
thanks a lot, that's all the information i wanted :) i will do my own research then.
Please see my comments to the Solution 1 by Ron Beyer.

In this situation, which I think we reasonably explained to you, it's the best to avoid using window.open. Apparently, you hardly can expect consistent behavior of different browsers (and even different versions of the same browser as they are developed) in respect to choice between creation of a new tab page or a new separate browser window, and this inconsistency will badly effect navigation experience of the users, especially the least experienced ones. Besides, pop-ups are evil. Conceptually, from the stand point of a Web application, creating a new tab page is still a popup.

The best UI design should leave the decision to create a new tab page or a new separate browser window to the user, at the moment of clicking on an anchor.

I would advise to use the alternative approach. This is one of the good alternatives:
http://jqueryui.com/dialog/[^].

You can find a lot of 3rd-party jQuery plug-ins to implement more sophisticated (but fully defined by your application) imitation of modal or popup behavior.

—SA
 
Share this answer
 
Comments
Ron Beyer 6-Sep-13 12:32pm    
+5'd, although there are instances when using new window (avoid pop-ups like the plague) is needed. Government websites for example with outside links, intranet sites with outside links, etc. Usually they are opened in new windows so that the user knows and acknowledges that they've left the site.
Sergey Alexandrovich Kryukov 6-Sep-13 21:20pm    
Thank you, Ron.
I totally agree with you when you say there are exclusion from the recommendation to avoid pop-ups, but as a rule of thumb it is useful.
My logic was this: it there is a controversy between new tab page and a new separate browser window, this an indicative concern when my recommendation should be well applicable.
—SA
Try this

C#
// open in default browser
    Process.Start("http://www.csharpdeveloping.net");


    // open in Internet Explorer
    Process.Start("iexplore", @"http://www.csharpdeveloping.net/");

    // open in Firefox
    Process.Start("firefox", @"http://www.csharpdeveloping.net/");

    // open in Google Chrome
Process.Start("chrome", @"http://www.csharpdeveloping.net/");

Happy Coding :)
 
Share this answer
 
v3
Comments
melvintcs 9-Sep-13 2:46am    
i duno why they put 1 star on this solution, it helped me pretty well, i modified and have a better soluion.
couldn't you just use System.Diagnostic.Process.Start("chrome", "http://www.google.com");
if chrome is already running it starts in new tab
 
Share this answer
 
Thank you Gitanjali Singh for sharing the code with us. Modified, and the code served me well :)

C#
System.Web.HttpBrowserCapabilities browser = Request.Browser;
          if (browser.Browser == "Chrome")
          {
              Process.Start("chrome", @"http://www.google.com/");
          }
          else
          {
             Response.Write("<script>window.open('http://www.google.com/');</script>");
          }


for whoever who wonder, you also can solve this problem by install the extension "One Window"
https://chrome.google.com/webstore/detail/one-window/papnlnnbddhckngcblfljaelgceffobn/related?hl=en[^]
 
Share this answer
 
v2
Comments
Gitanjali Singh 9-Sep-13 5:51am    
Thanks:)
melvintcs 10-Sep-13 23:50pm    
the code is not working after i upload to the server and use Chrome. any thought?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900