0

I am testing out the plugin "searchHighlight" to highlight search terms on our Search page when one searches for a keywords. The problem is that it only reads the referral URL and I do not know how to modify this so it only reads the current URL that your on instead of the referral.

I.e.

  1. I use our search box from my home page
  2. I search for 'glass door'
  3. Results come up on the search page but no highlighting
  4. I click a product with the words 'glass' or 'door' in it
  5. On the product page it highlights the words I searched for ('glass' + 'door')

Example URL Searched: http://tsqja.deznp.servertrust.com/SearchResults.asp?Search=glass+door&x=0&y=0

From the example I tried to give above you can see it is highlighting based off the Referral URL Keywords. I want it to use the actual search results. Given regex this is my search results page:

[/^http:\/\/(tsqja\.)?deznp\.servertrust/i,/Search=([^&]+)/i]

Anyone know how this can be achieved? Get highlighted search terms based off the above regex via jQuery preferably?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
ToddN
  • 2,901
  • 14
  • 56
  • 96
  • Well, it doesn't solve the problem, but it's really quite easy to get the query results of a page. You can get the current `?something=blah` part of a url with `location.search` – Joseph Marikle Sep 23 '11 at 13:48

3 Answers3

0

Try the SearchHighlight plugin for jQuery. They have a demo page here

Mika Andrianarijaona
  • 1,619
  • 17
  • 29
  • I've been using this, however it only reads the Referral. If I could modify the plugin to use only the URL I specify and NOT use the referral it would be perfect. – ToddN Sep 23 '11 at 13:54
  • I have also found this other [plugin](http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html)..seems really interesting – Mika Andrianarijaona Sep 23 '11 at 14:00
  • The debug_referrer option got me closer but again, the search results will be ON the search page. And I cannot specify every page on my site as a referrer...or can I? – ToddN Sep 23 '11 at 14:04
  • I am not sure you can and anyway they just intended it for debug so this is not the best solution on production i think. Give a try to http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html – Mika Andrianarijaona Sep 23 '11 at 14:09
0

Well, again it's not exactly the best solution...... but you could use this:

if(document.referrer !== location.href) location.reload()

That will reload the page if the current url is not the referrer. This will only run once provided the url is not constantly changed on page load.

Joseph Marikle
  • 76,418
  • 17
  • 112
  • 129
0

You can use the keys configuration option to set the highlighting up manually on the search page. You could use a small script to get the search term from the url using a regex, then pass the configuration into SearchHighlight:

// Get the keys from the URL using a regex
// http://stackoverflow.com/questions/901115/get-query-string-values-in-javascript
...

// Put the keys into the options
var options = {keys: "Glass Door"}
jQuery(document).SearchHighlight(options);

Using the keys option completely disables the referrer checking.

mmcnickle
  • 1,599
  • 10
  • 13
  • I have tried this and perhaps I need to revisit. I just need to create a function to grab the search term and throw it into 'keys'. Is this correct? – ToddN Sep 23 '11 at 14:10
  • Yes, you can see how it works (after you have found the terms) at their [demo page](http://www.jquery.info/scripts/SearchHighlight/demo_en.html). There should be some functions to grab the search term from the [page I included in the comments](http://stackoverflow.com/questions/901115/get-query-string-values-in-javascript). – mmcnickle Sep 23 '11 at 14:48