Tải bản đầy đủ - 0 (trang)
Hack 35. Create Large, Maintainable Bookmarklets

Hack 35. Create Large, Maintainable Bookmarklets

Tải bản đầy đủ - 0trang

Theessentialideainthiscodeisthatwedynamicallyinserta

newscriptelementintotheDOMthroughourbookmarklet.

HereisthecodewithinthebookmarkletURL,formattedtobe

morereadable:

functionloadScript(scriptURL){

varscriptElem=document.createElement('SCRIPT');

scriptElem.setAttribute('language','JavaScript');

scriptElem.setAttribute('src',scriptURL);

document.body.appendChild(scriptElem);

}

loadScript('http://216.203.40.101/projects/tutorials/'

+'creating_huge_bookmarklets/helloworld.js');



Thepreviouscodesamplecreatedanewscriptelementandset

ittothenewURL.Wethenappendthenewscriptblocktothe

document.Thescriptweappend,helloworld.js,isverysimple:

alert("HelloWorld!");



Whenthisscriptisloaded,the"HelloWorld!"messageappears

immediately.

TheloadScript()functiondefinitionandfunctioncallarerolled

intoasingleJavaScriptURLtoturnitintoabookmarklet.

Youcanenterthescriptyourselfbydraggingthelinktoyour

toolbar.Thennavigatetoanothersiteandclickthebookmarklet

link.Youwillseethemessage"HelloWorld!"appear,loaded

fromanexternalscript.

Theexternalscriptloadedthroughthebookmarkletcancome

fromadifferentdomainthanthewebsiteitself,openingthe

doortosophisticatedbookmarkletsthataggregatedatafrom



differentwebsites.Seehttp://www.bookmarklets.comforsome

oftheinterestingworkpeoplehavedonewithbookmarklets.

BradNeuberg



Hack36.UsePermanentClient-SideStoragefor

AjaxApplications



Useanopensourceframeworkthatallowsapplications

tostorelargeamountsofdatapersistentlyontheclient

side.

ThishackdescribestheAjaxMassiveStorageSystem(AMASS).

AMASSisanopensourcelibrarythatusesahiddenFlashapplet

toallowJavaScriptAjaxapplicationstostoreanarbitrary

amountofsophisticatedinformationontheclientside.This

informationispermanentandpersistent;iftheuserclosesthe

browserornavigatesawayfromthewebsite,theinformationis

stillpresentandcanberetrievedlaterbythewebpage.

Informationstoredbywebpagesisprivateandlockedtoa

singledomain,sootherwebsitescannotaccessthis

information.

AMASSmakesitpossibletostoreanarbitraryamountof

sophisticateddata,pastthe4Klimitofcookiesorthe64Klimit

ofInternetExplorer'sproprietaryclient-sidestoragesystem.



Seethesitehttp://codinginparadise.org/weblog/2005/08/ajax-internetexplorer-has-native.htmlfordetailsonInternetExplorer's64Kstorage

system.



AnAMASS-enabledwebsitecanstoreupto100Kofdata

withoutuserpermission.Abovethatlimit,thewebsitemust

promptusersforpermissiontostoretherequestedamountof



information.TheAMASSsysteminformstheclient-side

applicationwhetherthestoragerequestwasallowedordenied.

Intests,AMASShasbeenabletostoreupto10MBofuser

datawithgoodperformance.

AMASSworksonInternetExplorer6+andGecko-based

browserssuchasFirefox.UsersmusthaveVersion6+ofthe

Flashplug-ininstalledtouseAMASS,butaccordingto

Macromedia'sstatistics

(http://www.macromedia.com/software/player_census/flashplayer/

Flash6+isalreadyinstalledon95%ofmachines.

ThelatestreleaseofAMASScanbefoundat

http://codinginparadise.org/projects/storage/latest.zip;atthe

timeofpublicationthelatestreleaseofAMASSwasVersion

0.02andwasinalphadevelopment.AMASSisunderaBSD

license.



UsingAMASS

WorkingwithAMASSissimple.TheAMASSframeworkcreates

theabstractionofapermanenthashtablethatpersistseven

aftertheuserhasleftthepageorclosedthebrowser.

ThefirststepinworkingwithAMASSistoloadtheAMASS

script:







InordertouseAMASS,youmustwaitforitsinternalmachinery

tofinishloading.Tofindoutwhenthishappens,addalistener:

storage.onLoad(initialize);



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Hack 35. Create Large, Maintainable Bookmarklets

Tải bản đầy đủ ngay(0 tr)

×