entrepreneur  /  project manager  /  XHTML, CSS & JavaScript developer

View Source on iPhone

Apple iPhone

This is a cool little tidbit for those of you web developers that have an iPhone. A Safari bookmarklet that enables you to “View Source” for any web page while using Safari on the iPhone. A bookmarklet (in case you didn’t know) is “a JavaScript program stored as a URL within a bookmark” as defined by Wikipedia.

The steps that follow will walk you through the process…
 

1 - Select and “copy” the long string of code below…





 
* This needs to be one long continuous string, so if you’re cutting and pasting from Firefox, you’ll need to remove the line breaks and/or spaces.

 
2 - On your computer, go to ANY webpage in Safari and bookmark it using either the “+” (Add Bookmark) button or by choosing “Add Bookmark…” from the “Bookmarks” menu. When saving the bookmark name it “View Source” and save it wherever you’d like in your bookmark hierarchy.

3 - Now, go into the bookmark manager. Do this by clicking the bookmark icon in your bookmarks bar or by choosing “Show All Bookmarks” from the “Bookmarks” menu. Navigate to the bookmark you just saved.

4 - Single-click on the URL for the bookmark to highlight the text for editing, and paste the text/code you just copied above.

5 - Plug in your iPhone and sync it up w/ your bookmarks on your computer.
 

Now, to actually use it - launch your Safari web browser on your iPhone and navigate to whatever web page you would like to view the source code for. After the page has loaded, click the bookmark icon in the lower Safari navigation bar (3rd from the left), and navigate to your “View Source” bookmark and click it.

And there you have it.

 

JavaScript email cloaking

Here’s another quick one. Below is a simple JavaScript that you can use to cloak your email address when posting it on your website. It dynamically writes the email link into the page which will thwart most spambots (server-side creation of the email link will always be a little more secure). Here’s how we do it…

 
1 - create a new JavaScript file, name it “email.js”, and paste in the following…


var prefix = "username";
var suffix = "domainname.com";
var address = prefix + "@" + suffix;

document.write('<a href="mai');
document.write('lto:' + address + '">click here</a>');

 
2 - then place the following code in your page where you want the link to appear…


<script type="text/javascript" src="email.js"></script>

 
example:
 
<p>to contact me via email, please <script type="text/javascript" src="email.js"></script></p>

 
result:
 
to contact me via email, please

 
All you have to do is change 3 variables. The email prefix and suffix are in the first 2 lines of code in the external JavaScript file. The text to display for the hyperlink is in the last line of code (in this case - “click here”). It’s pretty self-explanatory.

 

  • stuff i’ve built

  • need my help?

    I’m currently available for off-site projects. So, if you’re in need of a client-side guru, or maybe just some help with customizing your own WordPress blog, you can contact me via email by

  • what i'm reading

     

  • what i'm using

    MacBook & Apple Cinema Display
    iPodiPhoneApple TV

     

    Apple Cinema Display MacBook
  • what i'm watching