How to search within a web page on your iPhone?

Search for text within a web page on mobile Safari on your iPhone.

It’s great that iPhone OS 3.0 has this neat Spotlight kind-of-a search feature that makes it a lot more convenient to search for anything on your iPhone. Let me take that word “anything” back, in fact you cannot search for a text within a web page on the Safari browser that comes with the iPhone.

No worries, there is a simple bookmarklet that you can add to your Safari browser on you iPhone to bring the “search within a web page” capability to your iPhone. The steps to get this up-and-running are pretty straight-forward.

Somehow get this Javascript code to your iPhone,

javascript:void%28s%3Dprompt%28%27Find%20text%3A%27%2C%27
%27%29%29%3Bs%3D%27%28%27+s+%27%29%27%3Bx%3Dnew%20RegExp%28s%2C
%27gi%27%29%3Brn%3DMath.floor%28Math.random%28%29*100
%29%3Brid
%3D%27z%27%20+%20rn%3Bb%20%3D%20document.body.innerHTML%3Bb%3Db.replace
%28x%2C%27%3Cspan%20name%3D%27%20+%20rid%20+%20%27%20id%3D%27%20+
%20rid%20+%20%27%20style%3D%5C%27color%3A%23000
%3Bbackground-color%3Ayellow%3B%20font-weight%3Abold%3B%5C%27%3E
%241%3C/span%3E%27%29%3Bvoid%28document.body.innerHTML%3Db%29
%3Balert%28%27Found%20%27%20+%20document.getElementsByName%28rid
%29.length%20+%20%27%20matches.%27%29%3Bwindow.scrollTo%280
%2Cdocument.getElementsByName%28rid%29%5B0%5D.offsetTop%29%3B

I just simply emailed it to me and so I can access the same from my iPhone.

Javascript emailed to Askar self-1.png

Make sure to copy the entire script and DO NOT miss out any.

DemoGeek.com site on iPhone Safari.png

Once copied, launch the Safari browser on your iPhone and get to any website, like DemoGeek.com (it doesn’t matter which one).

Add Bookmark button on iPhone Safari.png

Once there, tap on the “+” button at the bottom of the screen to start bookmarking the page. Tap on the “Add Bookmark” button to bookmark the page.

Adding bookmark to Edit Bookmark page.png

On the Edit Bookmark page type-in a name, like “Find In Page” for example, for the bookmark and the paste the Javascript code that you copied earlier. Save the bookmark.

Find In Page bookmark.png

That’s pretty much all set. Now, if you want to find a text within a web page, first get to that website and once there tap on the “bookmark” button at the bottom of the Safari browser. Locate the bookmark you’ve created earlier, in this case “Find In Page”, and tap on it.

iPhone keyword typed into Find In Page bookmarklet for iPhone.png

Mobile Safari will now open-up a dialog that asks you to enter a text or keyword to search for within the web page you have open.

Matches found for the search on the iPhone Safari.png

Once you hit the OK button, you’ll be presented with another dialog that tells you how many matches were found for the search term. That’s just a visual information before you get to the detail.

iPhone keyword highlighted on iPhone Safari.png

When you hit the OK button iPhone Safari will highlight the text that you’ve searched for within the web page.

That’s all to it! From now on whenever you need to search for a text within a web page just call up the “Find In Page” bookmark and start finding the text you want to find within a web page.

I hope you find this bookmarklet useful. If you see any other uses of this bookmarklet or if you’ve faced any issues with it please share you thoughts/comments.

[via]

Technorati Tags:
, , iPhone Customize, , , ,

Related Posts with Thumbnails


Subscribe to our free RSS feed to keep up with what's happening at DemoGeek.com

At DemoGeek.com we try to explain the tech stuffs in as much detail as we can to help the not-so-tech-savvy of our friends understand and follow the tech stuffs.

Share/Save/Bookmark

Subscribe to DemoGeek.com

21 comments so far

  1. smit
    #1

    the block of code you have provided is not working. Is it complete code?

  2. BRETTE
    #2

    THANK YOU!!!!

  3. demogeek
    #3

    Brette – I'm sorry but I found it hard to interpret what you meant. Can you be a bit more elaborative on your question?

    Thanks.

  4. Luis Sousa
    #4

    This is absolutely brilliant! However the iphone does not allow me to change the bookmark URL only the name… I am having to keep the code in Notes and copy and paste when I need to use it… am I missing something?

  5. demogeek
    #5

    Luis – which version of iPhone OS are you running? I know it's a painful thing to copy/paste the code. It actually is as simple as bookmarking a web page. Do you have any parental control settings that's preventing you from updating the bookmark URL?

  6. AlgesPT
    #6

    Are you sure you are in the Edit Bookmarks option?

    Its not possible to change the 'Bookmark URL' from the 'Add BookMark' option.
    You can, however, change the URL in the 'Edit Bookmark' option as shown.

    So thats where you should be changing the URL

  7. Chris
    #7

    Just found this hint and javascript solution; thank you! I've been annoyed that Apple didn't include this functionality for some time, and I appreciate the fix. Cheers!

  8. Annissa
    #8

    Thx for the first code snippet. It wrkd great :) I tried the updated code and also found it does not wrk. Thk u tho! I will def use the first code :)

  9. Tom
    #9

    I have the same question. On a Safari iPhone web page, I might see something like an address I want to copy. But double tapping just changes the zoom.

  10. Tom
    #10

    This didn't work for me either. The original did though. It looks like there's some missing code. This is what I can copy:

    javascript:void(l=%27%27);d=document.body;j=0;lrid=null;if(d.lastfind!=null&&d.lastfindrid!=null){l=d.lastfind;lrid=d.lastfindrid;}void(s=prompt(%27Find%20text:%27,l));if(s!=null&&s!=%27%27){if(s==l){j=d.lastfindindex+1;}else{b=d.innerHTML;if(lrid!=null){x=new%20RegExp(%27%3Cspan%20name=%22%27+lrid+%27%22%20id=%22%27+lrid+%27%22%20style=%22color:%20rgb%5C%5C(0,%200,%200%5C%5C);%20background-color:%20yellow;%20font-weight:%20bold;%22%3E([^%3C]%2A)%3C/span%3E%27,%20%27g%27);b=b.replace(x,%20%27$1%27);}d.lastfind=s;s=%27(%27+s+%27)%27;x=new%20RegExp(s,%27gi%27);rn=Math.floor(Math.random()%2A100);rid=%27z%27+rn;d.lastfindrid=rid;b=b.replace(x,%27%3Cspan%20name=%22%27+rid+%27%22%20id=%22%27+rid+%27%22%20style=%22color:%20rgb(0,%200,%200);%20background-color:%20yellow;%20font-weight:%20bold;%22%3E$1%3C/span%3E%27);void(d.innerHTML=b);alert(%27Found%20%27+document.getElementsByName

  11. Mike
    #11

    This is awesome, many thanks!

  12. Arnie
    #12

    Awesome idea! weird that apple hasn't done this yet. I can't get it to work though. No matter what i search it always says 0 results : (

  13. Tim
    #13

    Thanks a lot this is so awesome

  14. Lippa
    #14

    Never heard of bookmarklets before – but this one is awesome. Since my laptop died I have been using my iPhone for all my web browsing and this will help me greatly :)

    Thanks

  15. cialis
    #15

    Youre so cool! I dont suppose Ive read something like this before. So good to seek out somebody with some original thoughts on this subject. realy thanks for beginning this up. this website is one thing that’s wanted on the internet, somebody with a little bit originality. helpful job for bringing one thing new to the internet!

  16. rooby20112011
    #16

    Well done. I am satisfied with the calibre of the data offered. I expect that you continue with the exceptional work achieved.
    mesquite tx locksmith

  17. Corona Locksmiths
    #17

    I truly recognize that the strategies given is related to just about every person . Thanks a ton .

  18. Max
    #18

    awesome! Thanks

  19. Jake
    #19

    uhm…. you guys know that you can search a website for a word or phrase in the iphone safari by typing the word or phrase in the safari/google search bar and then scroll down to the "On this Page" section at the bottom of the suggestions list and click on Find "my phrase". It will highlight the phrase or word on the webpage and you can click on next to go to the next hit….

  20. Dan
    #20

    I had the same problem. add the bookmark with the name as "Find In Page" then go to bookmarks>find in page and then you should be able to change the url. e.g. make the bookmark, then change the url by editing it after it has already been created.

  21. Johannes
    #21

    This is f****** awesome. :)

    I don’t understand why apple is to stupid to implement this

Leave a Reply





XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

23 Trackbacks/Pings

About DemoGeek.com

DemoGeek.com brings you high quality articles, tutorials and how to's on everything related to Microsoft Windows, Mac OSX, iPhone, Useful Websites, Browsers, Software and Programming.

At DemoGeek.com you'll find step-by-step explanation of the technical issues explained in detail with screenshots and screencasts. Read More...

Contact |  FUG |  Disclaimer

Creative Commons License

Canonical URL by SEO No Duplicate WordPress Plugin