(Firstly, Chameleon does not run "on the front end" - it's a Python templating library which takes a string (your template) and a python dict (template parameters) as input and returns another string as its output. When sent to the client, that output is interpreted by the browser as a HTML page, possibly with embedded <script>
tags. The JavaScript in those tags is then executed by the browser - that's what runs on the client.)
Now, on to your question :) You can change the URL displayed in the browser's address string from JavaScript, which will insert a new entry into the browser's history. You'll also need to somehow ensure that your application can restore its state based on the information in that new URL, otherwise things will break if somebody bookmarks the URL, opens it in a new tab or simply reloads the application.
One, historically older, way of manipulating browser's history is by modifying the hash part of the URL via window.location.hash. Here's a minimal example:
<html>
<body>
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<input id="name-input" type="text" />
<script>
// restore the "application state" on page load -
// if there's a hash in the url we set the text in the input
if (window.location.hash) {
$('#name-input').val(window.location.hash.substring(1));
}
// whenever the hash changes (user clicked the Back button)
// we also need to modify the application state
$(window).on('hashchange', function () {
$('#name-input').val(window.location.hash.substring(1));
});
// type some text in the input and press Enter.
// Observe the URL changing. Try using the Back button.
$('#name-input').on('change', function () {
window.location.hash = $(this).val();
});
</script>
</body>
</html>
Another, more modern, way of modifying the history is via history.pushState(), which is more powerful but might require some server-side support (your server will need to be able to serve a correct page from the new URL your application transitioned to - if your URLs look like mysite.com/page1
, mysite.com/page2
, and you use pushState
to transition from /page1
to /page2
- the server needs to be able to handle both URLs).
You also need to be aware that there's a whole world of client-side frameworks built specifically to deal with this kind of situations (retrieving JSON data, rendering a page, modifying the URL), so maybe you'll find that using a client-side framework instead of doing things manually simplifies things. I'd start by looking at Backbone.js as it's pretty minimal and does not require you to do things in the "one and only true way" as some other frameworks.