2

I have the following code below in a javascript file and need to have the link that is being generated open in a new window.

   if (currentSearchType === 'extSearch') {
  extSearchSearchValue = extSearchSearchInput.val();
  window.location.href = replaceByObject(global.uhg.data['general'].body.extSearchSearchUrl, {
    q: extSearchSearchValue
  });

Normally with javascript I believe you'd use a window.open type of function, but not sure how to incorporate that with this type of code.

WhiteKnight
  • 4,938
  • 5
  • 37
  • 41
Roger
  • 23
  • 2

2 Answers2

1

However you do it, opening a new browser window with javascript will most probably be blocked by popup blockers, so perhaps you should rethink your approach to the user himself clicking a regular link, then you can use target="...".

Piotr
  • 4,813
  • 7
  • 35
  • 46
  • Probably is a stretch but frequently certainly. Absolutely unreliable expectation is the point. Further to this there's no guarantee of getting a new window vs a new tab anyway. – annakata Nov 11 '10 at 16:26
0

Just use a var to hold the URL and then pass it to window.open()...

if (currentSearchType === 'extSearch') {
  extSearchSearchValue = extSearchSearchInput.val();
  var url = replaceByObject(global.uhg.data['general'].body.extSearchSearchUrl, {
    q: extSearchSearchValue
  });

  window.open(url, 'searchWindow');
}
Josh Stodola
  • 81,538
  • 47
  • 180
  • 227