views:

44

answers:

2

At the moment to get to an external link from our intranet, we have to copy the link, and paste the link into a new window. Is there any way we can achieve this in a single function in javascript?

Thanks

UPDATE: When users login from outside the network, urls are changed. This is what we need to code for. I think I the following is applied twice, from server side and client side (this code is not editable):

  s=s.replace(/location.assign\(([^;]*)\)/g,"location.assign(alter_url($1))")
  s=s.replace(/location.replace\(([^;]*)\)/g,"location.replace(alter_url($1))")
  if(s.match(/location\s*=\s*([^;]*)(;?)/)!=null&&s.match(/\.open\(.+,.+,.*location\s*=.+\)/)==null)
   s=s.replace(/location\s*=\s*([^;]*)(;?)/g,"location=alter_url($1)$2")
  s=s.replace(/location\.href\s*=\s*([^;]*)(;?)/g,"location.href=alter_url($1)$2")
  s=s.replace(/window\.open\(([^,]*)(,.*)?\)/g,"window.open(alter_url($1)$2)")
  s=s.replace(/\.src\s*=\s*([^;]*)(;?)/g,".src=alter_url($1)$2")
  s=s.replace(/\.action\s*=\s*([^;]*)(;?)/g,".action=alter_url($1)$2")
  s=s.replace(/\.innerHTML\s*=\s*([^;]*)(;?)/g,".innerHTML=alter_html($1)$2")
  s=s.replace(/\.outerHTML\s*=\s*([^;]*)(;?)/g,".outerHTML=alter_html($1)$2")

Actually, the more I look at this, the more unrealistic it's becoming..

A: 

Right-clicking and choosing "Open in new window" doesn't work? Because if not, I'm not seeing a Javascript workaround working either. But:

You can open a new window with a specific URL (e.g., link) in Javascript easily enough:

window.open("http://stackoverflow.com");

And there are ways of getting the text that's selected in a page, to feed into that. All of which can be wrapped up into a bookmarklet so that the action becomes "select the text, click a link on the bookmark toolbar".

But if "Open in new window" doesn't work, I wouldn't expect that to work either.

T.J. Crowder
A: 

You can use the window.open to open the links on a new window. In fact, you could use a bookmarklet to set the target to _blank on every link on the site, in case you can't access the application source code.

BTW, if you hold the Shift key when opening the link it will open on a new window.

Adirael