Question

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.

Was it helpful?

Solution

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');
}

OTHER TIPS

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="...".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top