15.02.2013 Views

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

212<br />

<strong>JavaScript</strong> <strong>Examples</strong> <strong>Bible</strong>: The Essential Companion to <strong>JavaScript</strong> <strong>Bible</strong><br />

Example<br />

Listing 17-5 includes the unescape() function in front of the part of the script<br />

that captures the URL. This function serves cosmetic purposes by displaying the<br />

pathname in alert dialog boxes for browsers that normally display the ASCIIencoded<br />

version.<br />

Listing 17-5: Extracting the Directory of the Current<br />

Document<br />

<br />

<br />

Extract pathname<br />

<br />

// general purpose function to extract URL of current directory<br />

function getDirPath(URL) {<br />

var result = unescape(URL.substring(0,(URL.lastIndexOf(“/”)) + 1))<br />

return result<br />

}<br />

// handle button event, passing work onto general purpose function<br />

function showDirPath(URL) {<br />

alert(getDirPath(URL))<br />

}<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

pathname<br />

NN2 NN3 NN4 NN6 IE3/J1 IE3/J2 IE4 IE5 IE5.5<br />

Compatibility ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓<br />

Example<br />

See Listings 17-2 through 17-4 earlier in this chapter for a multiple-frame example<br />

you can use to view the location.pathname property for a variety of URLs of your<br />

choice.<br />

windowObject.location.pathname

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!