Created
April 2, 2012 21:18
-
-
Save mgroves/2287299 to your computer and use it in GitHub Desktop.
jquery AOP example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <head> | |
| <title>AOP with jQuery 1</title> | |
| <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js"></script> | |
| <script type="text/javascript" src="aop.min.js"></script> | |
| <script type="text/javascript"> | |
| $(document).ready(function() { | |
| $.aop.before( {target: window, method: 'DisplayUserAgent'}, | |
| function(args) { | |
| alert("About to execute DisplayUserAgent on element with id '" + args[0] + "'"); | |
| } | |
| ); | |
| $.aop.after( {target: window, method: 'DisplayUserAgent'}, | |
| function(returnVal) { | |
| alert("Done executing DisplayUserAgent. It returned: '" + returnVal + "'"); | |
| } | |
| ); | |
| DisplayUserAgent("txtExample"); | |
| }); | |
| function DisplayUserAgent(elementId) | |
| { | |
| $("#" + elementId).text(navigator.userAgent); | |
| return navigator.userAgent | |
| } | |
| </script> | |
| </head> | |
| <body> | |
| <p id="txtExample">This text will be updated with your user agent info</p> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment