How To Search Within a Web Page on the iPhone → Washingtons Blog
How To Search Within a Web Page on the iPhone - Washingtons Blog

Monday, November 23, 2009

How To Search Within a Web Page on the iPhone


Since I just bought an iPhone, I am learning - and will be posting - some tricks and shortcuts for making it more useful.

The iPhone G3 is a great smart phone and mobile computing device. However, it has some real blind spots. For example, you cannot do a basic search within a web page for words or phrases.

Here is the hack/workaround:

1) Open up your Safari web browser

2) Bookmark a page (by tapping the button)

3) Go into bookmarks (by tapping the button)

4) Click "Edit"

5) Select your new bookmark

6) Change the name to "Search" or "Find"

7) Delete the address

8) Copy and paste the following into the address box:

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
9) Save (by tapping Done)

Now surf as normal, and when you want to find something within a web page, choose bookmarks and select "Search" or "Find".

The following javascript dialog will pop up:

It works well.

10 comments:

  1. Very cool! Works like a charm! Is there any way you could write a script to trick websites into thinking an iPhone is not a mobile device? Some mobile sites are severely limited and don't provide a link to the full site. Thanks!

    ReplyDelete
  2. Thank you so much!!! Works like a charm!

    ReplyDelete
  3. I tried this right now on my iPhone 3gs!!!! This works perfectly!!!!!
    Thanks a lot for sharing this!!!!! :)

    ReplyDelete
  4. Simple yet clever - thanks!

    ReplyDelete
  5. Great, thanks! Somehow I got the impression that this feature of searching within a webpage was going to added to iOS 4, but so far apparently not. This is a great workaround, at least in Safari (rather than say, within Mail or Notes). Any suggestion from Apple that it plans to incorporate a similar feature anytime soon?

    ReplyDelete
  6. Just use the opera mini app. It has this feature built in

    ReplyDelete
  7. You can search web pages on iOS 4.2 now using the same box where you can search google / yahoo / bing. Just type and scroll down and it's below the suggestions.

    ReplyDelete

→ Thank you for contributing to the conversation by commenting. We try to read all of the comments (but don't always have the time).

→ If you write a long comment, please use paragraph breaks. Otherwise, no one will read it. Many people still won't read it, so shorter is usually better (but it's your choice).

→ The following types of comments will be deleted if we happen to see them:

-- Comments that criticize any class of people as a whole, especially when based on an attribute they don't have control over

-- Comments that explicitly call for violence

→ Because we do not read all of the comments, I am not responsible for any unlawful or distasteful comments.