title: Looking for a way to "emulate" full websites (incl. requests, history, URLs) as javascript examples within another page?
body: <p>I'm working on a website that displays html/css/javascript code examples. Something like a best practices library.</p>
  
  <p>Examples could look like this:</p>
  
  <ul>
  <li>How to implement full clickable teaser elements</li>
  <li>How a good heading outline should look like</li>
  <li>How keyboard focus should be managed in modal dialogs</li>
  </ul>
  
  <p>I'm using CodePen.io to create the examples, so users can try them out and play with them to their wishes.</p>
  
  <p>Every example is presented on a single webpage, and every example should be written only in HTML, CSS, and JavaScript (the things that CodePen.io provides).</p>
  
  <p>The only problem there is: how can I emulate (fake?) requests?</p>
  
  <ul>
  <li>For example, one of the examples will show how clicking on a button fires an AJAX call to a server, then displays an info somewhere on the page. In the background, it's not really an AJAX call, it's only a "fake" AJAX call that's handled by some JavaScript.</li>
  <li>Another example is navigating between pages: the URL should change (e.g. <code>examples/123/#index</code>, then after clicking a link it's <code>examples/123/#some-other-page</code>), but in fact, it's still the same page that's displayed again and again, but depending on the URL, some different content is displayed. Browser history needs to be working, too.</li>
  <li>One last example could be submitting a form and displaying input errors inline in the form: how can I get the POST data in an easy, and display the form again with errors?</li>
  </ul>
  
  <p>This could surely be done using plain JavaScript. But I'm sure there are libraries for doing stuff like that, I just don't know what to search for.</p>
  
  <p>In fact, what I'm describing are mini 1-page-applications. But I don't need a fully fledged framework like AngularJS, something very simple that can handle requests (incl. managing browser history and URLs) is enough for my purposes, I guess.</p>