SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 246 | Next

Richard Wagner

"Professional iPhone and iPod touch Programming: Building Applications for Mobile Safari"

You can either substitute %20 for a blank space
or let Safari do the conversion for you.
If the script returns a value, then it should be enclosed inside of void() to ensure that the JavaScript
code runs as expected. For example, the following Search Wikipedia bookmarklet displays a JavaScript
prompt dialog box (see Figure 10 - 1 ), and then calls a Wikipedia search URL using the user ??™ s value as the
search term:
javascript:t=prompt(???Search
Wikipedia:??™,getSelection());if(t) void (location.href=??™http://en.wikipedia.org/w/wiki
.phtml?search=??™+escape(t))
Figure 10-1: Search Wikipedia bookmarklet
Here ??™ s a second example that provides a front - end onto Google ??™ s define service:
javascript:d=prompt(???Define:??™,getSelection());if(d)void(location.href=??™http://
www.google.com/search?q=define:??™+escape(d))
Chapter 10: Packaging Apps as Bookmarks: Bookmarklets and Data URLs
223
Adding a Bookmarklet to Mobile Safari
Bookmarklets are normally added in a standard browser through a drag - and - drop action. However,
because that user input is not available in Mobile Safari, you need to add the bookmarklet through the
following process:
1. On your main computer, create your bookmarklet script and test it by pasting it into the URL
box of Safari.


Pages:
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258