473,395 Members | 2,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Search text inside a webpage

1
How can I search text and count its appearance inside a webpage?
I'll try NodeIterator and NodeFilter but there's an error "NodeFilter is undefined".
Jun 10 '07 #1
5 2360
sumittyagi
202 Expert 100+
How can I search text and count its appearance inside a webpage?
I'll try NodeIterator and NodeFilter but there's an error "NodeFilter is undefined".
I don't know about node filters, (havn't heard abt it), But you can iterate nodes, then check if it is a text node, and if it is then get its text and serach for your content.
Jun 11 '07 #2
dmjpro
2,476 2GB
I don't know about node filters, (havn't heard abt it), But you can iterate nodes, then check if it is a text node, and if it is then get its text and serach for your content.

How to check an element if it is text node or not?
Plz help.

Kind regards,
Dmjpro.
Jun 11 '07 #3
sumittyagi
202 Expert 100+
How to check an element if it is text node or not?
Plz help.

Kind regards,
Dmjpro.
Its very simple:
<script language="JavaScript"
type="text/javascript">
window.onload = function() {
var s = "";
with (document.getElementById("para")) {
for (var i=0; i<childNodes.length; i++) {
with (childNodes[i]) {
s += nodeName + ": " + nodeValue +
" (" + nodeType + ")\n";
}
}
}
window.alert(s);
}
</script>
<p id="para"><em>JavaScript</em> Phrasebook</p>


nodeType stores the info of type of node.
these are typical nodeTypes
Node Type
Description

1 Tag

2 Attribute

3 Text (includes whitespace)

8 HTML comment

9 Document

10 DTD

11 Fragment
Jun 11 '07 #4
acoder
16,027 Expert Mod 8TB
How to check an element if it is text node or not?
Check this example .
Jun 11 '07 #5
iam_clint
1,208 Expert 1GB
This is how i would get a word count
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3. <script>
  4. function countWords(word) {
  5. var fText = document.body.innerHTML;
  6. fText = fText.split(word);
  7. wordCount = fText.length-2;
  8. alert("Found the word '"+word+"' "+wordCount+" time(s) on this page");
  9. }
  10. </script>
  11. <input type="text" id="theword" value="word"><input type="button" onclick="var theword = document.getElementById('theword').value; countWords(theword);" value="Search">
  12. apples
  13. cherries
  14. apples
  15. pies
  16. quarters
  17. mexico
  18. mexico
  19. </body>
  20. </html>
  21.  
as an example
Jun 11 '07 #6

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

Similar topics

5
by: George | last post by:
Hi, Anyone has the background for explaining? I have made a search on my name and I have got a link to another search engine. The link's title was the search phrase for the other search engine...
2
by: khan | last post by:
hi guys, I want to search query through a webpage. I want to set search criaria a web text filed same we do for forms {forms]!!. is it possible I could use a webpage text field as a search...
3
by: mdh_2972 | last post by:
I have an array of over 1000 links in a .JS file. I do not want to put the whole thing on my page because it would take to long to render the page. So how can I randomly pick 1 element from the...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...
0
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,...

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.