Find Text Inside Page Script
Sep 12, 2002
Someone submitted this script my way, and I thought I'd post it here first, to see if people can come up with improvements.
This is a find text inside page script. Basically one would enter any text into a textbox, and the script searches for matches on the page, and highlights it if found. The script can be specified to search text in another frame or iframe.
Right now the script works in IE plus NS7. I was hoping it could be modified to work in NS6 as well.
View 15 Replies
ADVERTISEMENT
Apr 2, 2011
Is it possible to have a text box input searching for the entered text on another webpage in the same way Find In Page would do? I have a webpage that I want users to input an item, and that this will open the targeted webpage and bring you to (and highlight) the matched item(s) like find in page does. Is this possible or is the easiest way to just make users open the link to the target page and just complete the find in page search there?
View 1 Replies
View Related
Jul 9, 2002
People have complained that window.find() doesn't work, and everyone knows Gecko doesn't support IE's proprietary TextRange object, some have assumed you can't do this in Gecko.
On the contrary though:
Node.prototype.findTextMatches = [];
Node.prototype.findText = function(query, ignoreCase) {
this.findTextMatches.length = 0;
if (ignoreCase)
query = query.toLowerCase();
var tw = this.ownerDocument.createTreeWalker(this, NodeFilter.SHOW_TEXT, { acceptNode: function(node) {return NodeFilter['FILTER_' + (RegExp(query, (ignoreCase ? 'i' : '')).test(node.nodeValue) ? 'ACCEPT' : 'REJECT')] } }, true);
var offsets = [];
offsets[-1] = query.length * -1;
var totalMatches, trueOffsetDiff;
var range = this.ownerDocument.createRange();
while (tw.nextNode()) {
totalMatches = tw.currentNode.nodeValue.split(RegExp(query, (ignoreCase ? 'i' : ''))).length - 1;
for (var i = 0; i < totalMatches; i++) {
trueOffsetDiff = offsets[offsets.length - 1] + query.length;
offsets[offsets.length] = tw.currentNode.nodeValue.substr(trueOffsetDiff)[ignoreCase ? 'toLowerCase' : 'toString']().indexOf(query) + trueOffsetDiff;
range.selectNode(tw.currentNode);
range.setStart(tw.currentNode, offsets[offsets.length - 1]);
range.setEnd(tw.currentNode, range.startOffset + query.length);
this.findTextMatches[this.findTextMatches.length] = range.cloneRange();
}
offsets.length = 0;
}
return (tw.currentNode != this);
}
Node.prototype.highlightText = function() {
if (this.findTextMatches.length > 0) {
with (window.getSelection()) {
removeAllRanges();
addRange(this.findTextMatches.shift());
}
return true;
}
else
return false;
}
To search all text in the body, ignoring case, you'd go like:
document.body.findText('search query', true);
That loads up an array full of ranges selecting the text into document.body.findTextMatches.
To selectively highlight next occurences after executing findText:
document.body.highlightText();
// highlights first occurence
document.body.highlightText();
// removes previous selection, highlights second occurrence
// etc
Just calling that method over and over will successfully highlight instances. It returns true if it highlighted something, false otherwise,
Also, since I prototyped Node, it works not just in HTML documents, but can work in XML documents too.
Calling document.findText in an HTMLDocument may cause interesting results, as it searches through all the nodes, including <head>...
View 8 Replies
View Related
Aug 4, 2010
I wrote a function in PHP that converts characters for large strings. Here is the entire array:
[Code].....
View 2 Replies
View Related
Jul 13, 2007
Suppose I have <div id="outter"element. In side the div, I have
other <divand <imgelements. I used the following code
insideElementsList = outterDiv.childNodes;
for (var i = 0; i < list.length; i ++){
insideElementList[i] ...
}
In the loop, how can I know the current element is a <divor a <img>?
View 1 Replies
View Related
Jul 15, 2011
I am using jQuery 1.4 and can't afford upgrading just yet. I've been trying to find out how to find out how to find if a div has an image inside it. How would I go about doing this?
View 2 Replies
View Related
Aug 19, 2011
Basically we need to find a word which is inside a class and display a link.
So something like this find a word equal to "1 line custom" then display this <a href="/1-line-custom.htm">click here</a>
View 11 Replies
View Related
Nov 7, 2009
How can I find if each of the <p> tags contains <img> tag, then style the <p> tags which contain <img> inside them?
I have pre-set all <p> will have this style,code...
View 3 Replies
View Related
Jun 24, 2011
Code:
jQuery.fn.checkBoxTableHighlighter = function(){
return this.each(function() {
var $obj = $(this);[code]....
When the check box is checked (onload, click or keyup), if the table has a specified selector then i want to change the background color. I already have a working sample that i am converting to plugin. Since, my selector is at the table level, how can i find the checkboxes that are inside tr and td?
View 4 Replies
View Related
Jul 1, 2011
I'm trying to create a list of recipes which will on document ready all be hidden except the first one. And then when I click one of the dynamically added links (in a ul) in the sidebar I want the corresponding recipe to go from hidden to shown. I've managed to do everything really simply except I have no idea how to find the corresponding recipe when I click a link in the sidebar (the links link to the recipes with #recipe<number>)
$(".post").hide();
$(".post:first").show();
$("a[href*='#recipe']").click(function() {
$(".post").hide(600);
});
Somehow I need to access the id of the specific recipe, which I suppose should be possible since the clickfunction should store that somehow?
EDIT: I just realized that I could just use the href value as my id for the recipe (since its the same e.g. #recipe). However I'm having trouble using the variable that stores the href/id in the .show function.
$("a[href*='#recipe']").click(function() {
$(".post").hide(600);
var theHref = $(this).attr("href");[code]....
View 2 Replies
View Related
Oct 14, 2011
i have a requirement which i would like to solve with jQuery.I need to find all LI-elements which have a # as href url. The LI's are inside an div or ul with the ID=test.Then in the next step, when i loop through this items, i need to add a class=myclass to this elements. BUT it could be that there is no class tag at all, then it needs to be created or there is already a class, then i need to add myclass additonally.
View 7 Replies
View Related
Aug 15, 2010
I want to change the onkeyup attribute of a id="duration" textbox which is buried deep inside the DOM tree.
View 3 Replies
View Related
Nov 16, 2009
<h1>November<span>2009</span></h1>
making a variable equal the h1 html() without the span text.
// equals 'November2009'
var monthDelete = $('h1').html();
// I need just 'November'
View 1 Replies
View Related
Mar 26, 2009
how to find certain text within two specified text? In my example I have:
<asset:search
type=�asset type�
[subtype=�asset subtype�][code]...
I need to find through pages of code looking for "localfields=" between "<asset:search" and "/>".
View 5 Replies
View Related
Mar 12, 2010
I need to a code to do the following.
There is a Text Area that user can enter text. assume that user enter something and put a dot Following values should be populate in a drop down at the place where dot locate .
like when we get the string object using Net Beans IDE and when we put "Object." , drop down will be displayed with available methods for that particular object. idea is to build a editor using java script.
View 1 Replies
View Related
Mar 29, 2011
It is possible to perform a find in page search that looks at a specific link, opens the page in a new window and finds the text within that document?? Basically I regularly use an html page in work that has a list of people and their telephone numbers. I want to be able to type in a searchbox on my main page and it open the target page and find the name I am looking for? Is this possible or can you only Find In Page on the same page or another frame?
View 1 Replies
View Related
Jan 9, 2012
My DOM structure in HTML page have some elements 'IMG'. One of 'img' element have attribute 'src' = 'lolo1.jpg'. How can i find the 'DIV' element with this specific 'img' element inside? I have to find nearest 'DIV'.
[Code]...
I wanna write function like a GetNearestDivID('lolo2.jpg') which would give me result 'mix2'
View 1 Replies
View Related
Jun 15, 2011
I am trying to find a word inside a string.the search his going fine but I need to know which word has been found in the string.
Code:
Code:
Now in the string only one value can be found at a time.So its either a1 or a2 or so on.....
View 4 Replies
View Related
Mar 29, 2011
It is possible to perform a find in page search that looks at a specific link, opens the page in a new window and finds the text within that document? Basically I regularly use an html page in work that has a list of people and their telephone numbers.I want to be able to type in a searchbox on my main page and it open the target page and find the name I am looking for?Is this possible or can you only Find In Page on the same page or another frame?
View 1 Replies
View Related
Aug 14, 2007
I would like to find all elements within my DOM that begin with "test". Any idea on how I would go about this?
Example Below I would like to return a list of element id's of test1, test2, test3
<html>
<body>
<div id="spacer">
<div id="test1">Blah</div>
<div id="test2">Blah</div>
</div>
<div id="test3">Blah</div>
</body>
</html>
View 2 Replies
View Related
Jun 10, 2011
I'm trying find a text in all document with jQuery, for example:
It searches the text with % in front, and then adds a tag "a" after the text.
<body>
%ilovejquery
<div id="im>%ilovejquery</div>
<p>%ilovejquery</p>
</body>
In addition to seeking the text, I wanted to add a link around each. Example:
<body>
%<a href="#">ilovejquery</a>
<div id="im">%<a href="#">
ilovejquery</a></div>
<p>%<a href="#">
ilovejquery</a></p>
</body>
</body>
I think with REGEX is avaliable and $.each method.
View 4 Replies
View Related
Feb 15, 2007
I am creating a little html editor, and I want to highlight a chunk of
unformatted text, click a <buttonand put a <pand the beginning and
a </pat the end. I assume there is a DOM element relating to this,
can anybody help please ?
View 1 Replies
View Related
Apr 21, 2010
I do the following:
var testdata = '<?xml version="1.0" encoding="UTF-8"?><menu><menuitem title="Accueil">data/page_de_garde.html</menuitem></menu>';
alert($(testdata).find("menuitem").text());
It is quite simple and works with both firefox and chrome.Unfortunately, IE8 display an empty alert box.
Note: I also tryed.find("\menuitem") and.find("\:menuitem")
View 3 Replies
View Related
Jun 10, 2009
[code]...
Anyone got any tips on how to find out if the last letter of my label is 'F'?
View 4 Replies
View Related
Feb 11, 2011
I am looking for jQuery plugin that can give difference between two textarea content in some highlighted color.
View 1 Replies
View Related
May 27, 2009
Im trying to find a static way to see if someones typing, entered text etc... Currently, if you are typing, or enter anything in the input box it will say you are typing, and if u delete it, the message dissapears.. is there a way where if you're not typing at all it can say "You entered text" or something? maybe a way to time when the last key was pressed?
[Code]....
View 4 Replies
View Related