Skip to content

Instantly share code, notes, and snippets.

@mgroves
Created April 2, 2012 21:18
Show Gist options
  • Select an option

  • Save mgroves/2287299 to your computer and use it in GitHub Desktop.

Select an option

Save mgroves/2287299 to your computer and use it in GitHub Desktop.
jquery AOP example
<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