Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Finding Text on a Page
Old 03-14-2011, 07:24 PM Finding Text on a Page
FGU
FGU's Avatar
Super Talker

Posts: 116
Trades: 0
Hi,

I'm trying to find a way to look for a certain text to appear on a site. If the text appears, a popup comes up and alerts the users. If the text is not found, it doesn't do anything.

I did a little research and found that it probably could be done with PHP, but with the sheer amounts of "refreshing" this script might have, I thought it'd be better if it didn't trigger a trip to the server every time.

I did a little research, and saw that I could probably use the window.find method to use this.

The window is on another site, so I was thinking of using an invisible iframe for this, and placing it on there. I'm not sure if the javascript would search through the iframe though.

I found this simple little search code on google:
Code:
<head>
    <script type="text/javascript">
        function FindNext () {
            var str = document.getElementById ("findInput").value;
            if (str == "") {
                alert ("Please enter some text to search!");
                return;
            }
            
            if (window.find) {        // Firefox, Google Chrome, Safari
                var found = window.find (str);
                if (!found) {
                    alert ("The following text was not found:\n" + str);
                }
            }
            else {
                alert ("Your browser does not support this example!");
            }
        }
    </script>
</head>
<body>
    <div>LaLa, Lala, laLa , lala, lalala, tralala, some other text</div>
    <br />
    <input type="text" id="findInput" value="lala" size="20" />
    <button onclick="FindNext ();">Find Next</button>
</body>
and I was thinking of turning it to:
Code:
<head>
    <script type="text/javascript">
        function FindNext () 
           var str;
str="blahblah";
           
            
            if (window.find) {        // Firefox, Google Chrome, Safari
                var found = window.find (str);
                if (!found) {
                    alert ("The following text was not found:\n" + str);
                }
            }
            else {
                alert ("Text not found!");
            }
        }
    </script>
</head>
<body>
    <div>LaLa, Lala, laLa , lala, lalala, tralala, some other text</div>
    <br />
    <input type="text" id="findInput" value="lala" size="20" />
    <button onclick="FindNext ();">Find Next</button>
</body>
What would I need to change, as I'm not familiar with javascript and have an instinct that the above code has an error with it.

Thanks,
FGU is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-14-2011, 07:31 PM Re: Finding Text on a Page
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
The window is on another site, so I was thinking of using an invisible iframe for this, and placing it on there. I'm not sure if the javascript would search through the iframe though.
Javascript can only search the page (and hostname) it is on.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 03-14-2011, 08:14 PM Re: Finding Text on a Page
FGU
FGU's Avatar
Super Talker

Posts: 116
Trades: 0
Quote:
Originally Posted by chrishirst View Post
Javascript can only search the page (and hostname) it is on.
So even if its in an iframe on the page, it wouldn't work?

Is there any other way I could accomplish this with javascript?
FGU is offline
Reply With Quote
View Public Profile
 
Old 03-15-2011, 05:44 AM Re: Finding Text on a Page
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Nope, the page in the iframe is external to the current page.

A Google search brought up this page
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 03-15-2011, 09:30 PM Re: Finding Text on a Page
FGU
FGU's Avatar
Super Talker

Posts: 116
Trades: 0
So,

here's what I was thinking of doing it.

Using javascript onload, I would grab the content from the iframe and dump it into an invisible div (using CSS).

Then, I could go ahead and use the above code and find text.

Theoretically, would this work?

Thanks.
FGU is offline
Reply With Quote
View Public Profile
 
Old 03-16-2011, 06:06 AM Re: Finding Text on a Page
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
Did you read the link Chris gave? And thank him for it?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is online now
Reply With Quote
View Public Profile
 
Old 03-16-2011, 10:56 AM Re: Finding Text on a Page
FGU
FGU's Avatar
Super Talker

Posts: 116
Trades: 0
Quote:
Originally Posted by PaulW View Post
Did you read the link Chris gave? And thank him for it?
Yea, I read it and saw that it was about grabbing the content from the iframe, so I updated my proposed solution accordingly.

A friend recommended that I use PHP/cURL. I'm really rusty on PHP and clueless at cURL.

Would the PHP/cURL combination or javascript solution be more feasible?

Thanks.
FGU is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Finding Text on a Page
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.65088 seconds with 12 queries