using js to open links in current window, new window, or in the background

There are times to open links in the current window, sometimes in a new window, sometimes in background. Here is how to do it.

function open2(url, opt){
  if (opt == 0) // current window
    window.location = url;
  else if (opt == 1) // new window;
  else if (opt == 2) // background window
    {; self.focus();}

The syntax is a bit confusing, I guess these should be standardized in the future.

Ref link:

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s