| |||||||||||
JavaScript: find in page [iframe] Posted by jon@joco.myrf.net (JoCo), 28 September 2007 I have a page with an iframe on it pointing to another page. I am trying to create a search form on the main page to search for text on the child page. So far i'm not having much luck, as when you search it just refreshes both pages [table][tr][td] var TRange = null; var dupeRange = null; var TestRange = null; var win = null; var nom = navigator.appName.toLowerCase(); var agt = navigator.userAgent.toLowerCase(); var is_major = parseInt(navigator.appVersion); var is_minor = parseFloat(navigator.appVersion); var is_ie = (agt.indexOf("msie") != -1); var is_ie4up = (is_ie && (is_major >= 4)); var is_not_moz = (agt.indexOf('netscape')!=-1) var is_nav = (nom.indexOf('netscape')!=-1); var is_nav4 = (is_nav && (is_major == 4)); var is_mac = (agt.indexOf("mac")!=-1); var is_gecko = (agt.indexOf('gecko') != -1); var is_opera = (agt.indexOf("opera") != -1); var frametosearch = 'display'; function search(whichform, whichframe) { if (is_ie4up && is_mac) return; if (is_opera) return; if(whichform.findthis.value!=null && whichform.findthis.value!='') { str = whichform.findthis.value; win = whichframe; var frameval=false; if(win!=self) frameval=true; // this will enable Nav7 to search child frame win = parent.frames[whichframe]; } } else return; // i.e., no search string was entered var strFound; if (is_not_moz) whichform.findthis.focus(); } if (is_ie4up) { if (TRange!=null) { TestRange=win.document.body.createTextRange(); if (dupeRange.inRange(TestRange)) { TRange.collapse(false); strFound=TRange.findText(str); if (strFound) { win.document.body.scrollTop = win.document.body.scrollTop + TRange.offsetTop; TRange.select(); } } else { TRange=win.document.body.createTextRange(); TRange.collapse(false); strFound=TRange.findText(str); if (strFound) { win.document.body.scrollTop = TRange.offsetTop; TRange.select(); } } } if (TRange==null || strFound==0) { TRange=win.document.body.createTextRange(); dupeRange = TRange.duplicate(); strFound=TRange.findText(str); if (strFound) { win.document.body.scrollTop = TRange.offsetTop; TRange.select(); } } } if (!strFound) alert ("String '"+str+"' not found!") // string not found } // --> [/td][/tr][tr][td] <head> <script src="/findinpage.js" type="text/javascript" language="javascript1.2"></script> </head> <body> <script> if( ( document.body && document.body.createTextRange ) || window.find ) { document.write( '<form action="" onSubmit="searchForText( this.elements[0].value, window ); return false;">'+ '<input type="text" size="15"> <input type="submit" value="Find in Page"></form>' ); } </script> <iframe align="bottom" scrolling="auto" frameborder="0" width="100%" height="100%" name="display" id="display" src="software.html"></iframe> </body> [/td][/tr] [/table] I'm sure i'm probably missing something here but i have scoured the code to the best of my limited knowledge and am lost.http://iftown.com/sf.php Posted by admin (Graham Ellis), 29 September 2007 on 09/28/07 at 19:55:50, JoCo wrote:
My Javascript is very limited too, and it would take me an age of learning to get into this. Anyone else have any ideas? JoCo - are you able to provider a shorter example showing the problem / have you tried trimming out all the excess and seeing if that helps to distill the problem? Posted by jon@joco.myrf.net (JoCo), 29 September 2007 I know there is something definitely wrong with the coding as i can't even get it to search text on the parent frame. Do you possibly know of a better way of accomplishing this task?Doesn't necessarily have to be java, I just haven't been able to find any docs on other languages that would accomplish this. again I would first like to just create a find in page dialogue for people to search with. Almost exactly like the CTRL+F function in most browsers (is there a script to just open this for them?). I will worry about the iframes after I get that down first. Posted by admin (Graham Ellis), 30 September 2007 I would tend to code "server side" for a seach - probably more through my background than because it's the best way to do it in your case. After all, I have a search on this site that works for 9000 pages!This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |