473,787 Members | 2,931 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Highlight and scroll to search terms when referring URL is a search results page.

1 New Member
Hello,

I'm trying to parse the referring url for google search terms so that when this page loads it will scroll to and highlight the search term(s). Should i be using document.referr er?

Please take a look at my code and tell me what i'm doing wrong:
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
  2. <html lang="en"> 
  3. <head> 
  4. <title>highlight</title> 
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
  6.  
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript"> 
  2. function URL2Query() 
  3. var query = document.referrer("?",""); 
  4. var Q = query.split("&"); 
  5. var hash = {}; 
  6. for(var i=Q.length-1;i>=0;--i) 
  7. var q = Q[i].split("="); 
  8. if(q[0]) hash[q[0]]=unescape(q[1]); 
  9. return hash; 
  10.  
  11. window.onload=function(){ 
  12. var queryString = URL2Query(); 
  13. var contents=document.body.innerHTML; 
  14. var idx=contents.search(queryString.query); 
  15. if(idx!=-1) { 
  16. contents=contents.replace(queryString.query,'<span id="highlight">'+queryString.query+'</span>'); 
  17. document.body.innerHTML=contents; 
  18. document.getElementById('highlight').scrollIntoView(); 
  19. }; 
  20. </script> 
Expand|Select|Wrap|Line Numbers
  1.  
  2. <style type="text/css"> 
  3. #highlight {background:yellow;} 
  4. </style> 
  5.  
  6. </head> 
  7. <body> 
  8. <script> 
  9. document.write(document.referrer); 
  10. </script> 
  11.  
  12. <h1>Nirafo</h1> 
  13. <p>Aphasm escit ra apovum ecripsat. Quorepl alist osmephum ime itasmotis to eleh. 
  14. Quadeth est. Coticreus oce ro omuf ari trolodeus est. Nosm est. Thihopsiem, 
  15. minus beh brofiprue teranis. </p> 
  16. <h2>Smopada</h2> 
  17. <h2>Edrecram Ol <a href="highlight2.htm">Quorobucranis</a></h2> 
  18. <h3>Funap</h3> 
  19. <p>Ohusch ifemes, presn mapliant ple pupriem nalaho. Acrutra son cro teton hi 
  20. prenaquid est. Ocophiant asi pso bratetriem eta cragasch est. Volespes in 
  21. aplasnem usnerhant. Gerociant ina quidu tefum ag hiphue est. </p> 
  22. <p>Trog crin maquor on crebatuer tes efascranis. Ehisc pibisnam snatofas, ic 
  23. smot pel vavetont. Drup nicrus quido edesmiem plarodonis. Ugepsiant sosch log 
  24. fathon atahotis. Stim dabr quorimapseus vi dathat ufo lequadat. Quoreh muspeus 
  25. quidicusp, bro psopl tutist ropinuer. Schops tremorh, otusm lusagore dro 
  26. aquorospore pluvusmont. Socelum in rhetapa tumotis. Tof, vufucrue ul uquadicrum 
  27. ulovant. Smotr ruquidi ipreprant, an ugist popupr mucanis. Acron osmac ipeh vav 
  28. iloquader quadi govedas. Das mipacras, scet roteprore tin tabesch opod. Escreh 
  29. quadot dipapam nan hubo bre etomas. Sorhiant, vasta quoro opraquoriant 
  30. meriplotis. </p> 
  31. <p>Apoquid equoraphes mo buthi apretrotis. Fasm ohesmus, phud planerhes pe 
  32. mafothius itohonis. Brigiquorum in imischius vicrat. Smubr est. Orhan ipsev 
  33. tigigue ana omosmer ide tacront. </p> 
  34. <h3>Omorue</h3> 
  35. <p>Escol tosn umequidem vef asmibrer vi poricatis. Rothiem ef ano olotreus ah 
  36. stepephum est. Elicr osnepla baquadont, hes thisp osmicriant quidoteplant. 
  37. Ipricreus in falusmam esmobrat. Losch brebuquadum vi scasuquidam psenerer. Nasm 
  38. trunopsit ac regabue tobiscro. Scropl thabipiant at tequadore raciquidat. 
  39. Thatoscrus psinorat, staquad letore rhu dam moscuer. Gunit spisp to tahius 
  40. abribruer. Rhol brim asarus ahe epifer ega lononont. Stuph laspa ubi spimason 
  41. palanis. Rilebrue in alabon anabruer. Losm eda toh itrismeus schi rismus est. 
  42. Brov trotiphue eni ditob abrecras. </p> 
  43. <p>Scrapabrue in ololum ihaschotis. Uphar est. Soquid oquorephem hec stoniquadus 
  44. catasp. Anosc escruquad ip ihetha listonis. Mes in mirus uhiscanis. </p> 
  45. <h3>Pre Obaquad Nohequorant</h3> 
  46. <p>Thoph rutuphem, schin nobram ah ivascon psahitotis. Esmal quorabiteus ehi 
  47. dimequor cunavanis. Arhel odagus pse ospaquideus psotamont. Metoquidi pre ohe 
  48. vaquidam sce icimius est. Spast thesepus ime gafore apriquadatis. </p> 
  49. <h2>Rhenosmanis</h2> 
  50. <h3>Tah Conedit Drageschat</h3> 
  51. <p>Cril mepam spihecront, im psen scrumirham devath. Ciquid scar ladam thu 
  52. comanatis oro etrusmas. Thol diprem, uthuf piva ob phetepses craramatis. Epirh 
  53. est. Ohasc pufim im otagit matiphas. Osmod locuscam, ulerh givescam alo 
  54. ferespius familonis. Idabreus quorid ha phogemiem imeplont. Osith busnem 
  55. scrapinant, ta craf ethosn losmonis. Pofiem gi ilu lapemem eg opadrius est. 
  56. Breps snesascram, asath abuquadeus ho nophes vupodont. Quorideham, corap et 
  57. scriperem schohuto. Path tesothius noper, dru quadicr atradr ehapsant. Smes 
  58. uton, quidap scerosch tre pibiniant poher. </p> 
  59.  
  60. </body> 
  61. </html>
Sep 4 '07 #1
2 2924
pbmods
5,821 Recognized Expert Expert
Heya, Celeste. Welcome to TSDN!

Changed thread title to better describe the problem (did you know that threads whose titles do not follow the Posting Guidelines actually get FEWER responses?).

Please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.
Sep 4 '07 #2
acoder
16,027 Recognized Expert Moderator MVP
Expand|Select|Wrap|Line Numbers
  1. document.referrer("?","");
should use replace:
Expand|Select|Wrap|Line Numbers
  1. document.referrer.replace("?","");
What happens with your code? Do you get any errors?
Sep 5 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
5020
by: leegold2 | last post by:
Commonly done, eg. you enter a word in a search engine and when a hit-page comes up the search word(s) are highlighted. I'm doing a fulltext search that works well but I've tried a few "packaged scripts" and haven't got one to work yet. I'm looking for straightforward understandable way to do this on my MYSQL/PHP pages. Thanks, Lee
8
2061
by: Craig Cockburn | last post by:
Hi I'm aware of the use of robots.txt and the use of <META NAME="ROBOTS" CONTENT="index,follow"> However, what would be more useful is to be able to control within a page which elements of the page should be indexed and seen by robots and which elements are simply page furniture and it is safe to ignore or not cache (e.g. adverts).
2
2444
by: Daniel Di Vita | last post by:
I have created an ASP.NET page that allows the user to page through a result set. I need to expand on this. On that same page I a filed where the user can type in a search string. When they click a button ALL the results will be returned and the closest match to the search string will be highlighted. The approach I am taking to page the data is to put the keys/indexes into an array then create another data reader based on those results to...
4
1500
by: shapper | last post by:
Hello, I am creating a search engine which searches keywords inside SQL database and displays the results in a web page. In the results web page I would like to give a grey background to the words which were used as Keywords for the search. How can I do this?
11
3527
by: emailus | last post by:
I am webmaster for the domain <www.alpha1.org.au>. Not being an expert in html, I take advantage of my domain Registrant's web building tool, 'Instant Website'. This tool is provided as part of the fee I pay for web hosting. 'Instant Website' provides the option of having your opening page as a Flash Page, which you'll see if you visit <www.alpha1.org.au>. Well, you'll see it if you visit from a Windows machine. For some reason, when...
3
2290
by: tirath | last post by:
hi, I have a DataView which has around 50 items(the page has scrollbars). there is a search box on top of the page. when user enters an Id, i do DataView.find("Id"). I get the row index but i need to highlight this row and set focus on this row. that means my page might have to scroll down if the id that is searched happens to be the 45th one. Please help me do this.
1
7552
Merlin1857
by: Merlin1857 | last post by:
How to search multiple fields using ASP A major issue for me when I first started writing in VB Script was constructing the ability to search a table using multiple field input from a form and having the sql statement dynamically built according to the input provided by the user. I have used the method described here hundreds of times it is quick and adaptive. I generally use a frames page for the search, in this way the search is maintained...
1
3102
by: wmbrae | last post by:
I trying to make a javascript document reader in 2 frames. The left frame displays the document, the right frame shows a list of document links. This is as far as I got http://www.geocities.com/viewdoq/opening.htm (there are Firefox and Ie, and Ie version incompatiblities and clean-up which I will work on later) Does anybody have one ready made? I'd like to load the document and move the scroll position to where it was last viewed.
1
1778
by: db007 | last post by:
Hi, I have a problem with a current project and the scroll position. I have an AJAX enabled website using Visual Studio 2005 and ASP.Net 2.0. The project also uses masterpages. On the page in question, there is a search section in an AJAX update panel, situated on the left hand side. Upon submitting criteria and pressing a button, the results are displayed on the right hand side of the page.
0
9655
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5535
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4069
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.