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.

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

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

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.

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.

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.

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.

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.

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:
Browser, iPhone, iPhone Customize, iPhone How To, iPhone Safari, iPhone Tips, iPhone Tricks


December 11th, 2009 at 1:40 am
the block of code you have provided is not working. Is it complete code?
December 16th, 2009 at 10:54 pm
THANK YOU!!!!
December 16th, 2009 at 11:26 pm
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.
December 19th, 2009 at 9:19 am
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?
December 19th, 2009 at 11:46 pm
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?
December 29th, 2009 at 8:40 pm
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
January 9th, 2010 at 8:27 pm
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!
May 13th, 2010 at 12:23 pm
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
June 5th, 2010 at 7:52 pm
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.
June 5th, 2010 at 7:53 pm
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
October 20th, 2010 at 10:39 pm
This is awesome, many thanks!
October 23rd, 2010 at 7:23 pm
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 : (
December 9th, 2010 at 10:04 pm
Thanks a lot this is so awesome
January 1st, 2011 at 8:34 am
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
January 22nd, 2011 at 5:18 am
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!
April 13th, 2011 at 4:31 am
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
April 20th, 2011 at 5:48 am
I truly recognize that the strategies given is related to just about every person . Thanks a ton .
July 1st, 2011 at 3:57 am
awesome! Thanks
August 3rd, 2011 at 7:35 am
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….
November 20th, 2011 at 6:39 pm
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.
December 10th, 2011 at 5:56 pm
This is f****** awesome.
I don’t understand why apple is to stupid to implement this