I use a search engine on my web site www.barmirrors.com I got it from Search Site Pro. It opens the search results in the same window thus making it hard to get back to where you came from. I would like the search results to be dispalyed in a new window. Here is the code I am using. I'm hoping it can be changed to open the results in a new window. Can this be done? Thanks in advance!
Joe

<!-- Start of Site Search Pro code -->
<script language="JavaScript"><!--
var remoteURL = 'http://www.barmirrors.com';
var sURL = remoteURL +'/searchpro/form.php?mode=js&s=1&t=1';
document.write('<script language="JavaScript"' +
'src="' + sURL + '"><\/script>');
//--></script>
<!-- End of Site Search Pro code -->

Dani AI

Generated

Short explanation and practical fixes

The script included in the original post injects the search form/handler dynamically, so adding attributes to the script tag itself won’t change how the generated form sends results — which explains why ’s attempt had no effect. ’s window.open idea points in the right direction; the cleaner approaches are either (A) add a small client-side script after the widget to open the results in a new window/tab, or (B) edit the PHP/ASP file that generates the form so the form or its submit handler targets a separate window.

Client-side interception (place this after the provider script)

<script>
document.addEventListener('DOMContentLoaded', function () {
  var f = document.querySelector('form[action*="searchpro"], form[name*="search"]');
  if (!f) return;
  f.addEventListener('submit', function (ev) {
    ev.preventDefault();
    var action = f.action || window.location.href;
    var params = new URLSearchParams(new FormData(f)).toString();
    var sep = action.indexOf('?') === -1 ? '?' : '&';
    var url = action + sep + params;
    var w = window.open(url, 'searchresults');
    try { if (w) w.opener = null; } catch (e) {}
  }, false);
});
</script>

If the provider’s code calls form.submit() directly (which bypasses the submit event), override the form’s submit method instead:

<script>
(function(){
  var f = document.querySelector('form[action*="searchpro"], form[name*="search"]');
  if (!f) return;
  var orig = f.submit;
  f.submit = function () {
    var url = f.action + (f.action.indexOf('?') === -1 ? '?' : '&') + new URLSearchParams(new FormData(f)).toString();
    var w = window.open(url, 'searchresults');
    try { if (w) w.opener = null; } catch(e){}
    // intentionally do not call orig() to avoid navigating the parent window
  };
})();
</script>

Notes and troubleshooting

  • Put these snippets after the search widget so they see the generated form.
  • Pop-up blockers will allow a window opened directly from the submit handler but may block opens from async callbacks.
  • If the script files you installed on the server (the PHP/ASP versions mentioned) can be edited, change the generated form output there for a permanent server-side fix.
  • Mentioned contributors: , , — their suggestions point to the correct techniques; the snippets above show robust, non-invasive ways to force results into a separate window.

Recommended Answers

All 4 Replies

try using target="_blank" after the src attribute

That didn't seem to work for me. I tried putting the

target="_blank

almost everywhere in the script and the search results still opened in the same window. Maybe I didn't pinpoint it exactly. Any help is appreciated. Here is the search code again unaltered.

<!-- Start of Site Search Pro code -->
<script language="JavaScript"><!--
var remoteURL = 'http://www.barmirrors.com';
var sURL = remoteURL +'/searchpro/form.php?mode=js&s=1&t=1';
document.write('<script language="JavaScript"' +
'src="' + sURL + '"><\/script>');
//--></script>
<!-- End of Site Search Pro code -->

Hmm... your script just uses external URL for the link. It does not try to open a new window for the link. Could you try the code below instead? (not verify it myself... just off the top of my head...)

document.write("<a href=\"javascript:window.open('"+sURL+"')\">Search Link</a>")

First of all I want to thank those who have tried to help! Now I think I might be approaching this situation incorrectly. There are two files that were added to my web site when I purchased the search engine. They are titled 1)ASP version and 2)PHP version. Maybe the solution lies in altering the code or programming in one of these files??? If someone thinks they can help, I can post the code found in these files. I am a dummy when it comes to javascript or programming. Any help would be super appreciated!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.