DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

How To Open Links In Current Window, New Window, Background.

10.27.2006
| 166927 views |
  • submit to reddit
        
function open2(url, opt){
  if (opt == 0) // current window
    window.location = url;
  else if (opt == 1) // new window
    window.open(url);
  else if (opt == 2) // background window
    {window.open(url); self.focus();}
}
    

Comments

Carla Brian replied on Thu, 2012/07/26 - 7:32pm

Good tips by the way. I want to learn how to do this one. Good thing  I saw your post. - Mercy Ministries

Snippets Manager replied on Wed, 2010/06/09 - 8:33am

I've been looking all over for this *seemingly* simple thing. Thanks alot for solving my life problems in a few lines of code. *POST MOAR*