title: Get requested URL in Javascript
body: <p>I need to find the requested URL in Javascript (not the current URL) to identify which of two displayed sites is loaded.</p>
  
  <p>Scenario: I'm currently building a module for the Icinga Web 2 which has the option the show two frames (two separate .phtml files) side by side. When two of these frames are open, the URL shown in the browser looks as follows:</p>
  
  <pre><code>http://host/icingaweb/mymodule/siteA#!/icingaweb/mymodule/siteB
  </code></pre>
  
  <p>You can reload the single frames separately by clicking a button on it. In the browser log (and apache log) you can see, that for each load just the specific page is requested:</p>
  
  <pre><code>// reloading siteA
  GET http://host/icingaweb/mymodule/siteA
  // reloading siteB
  GET http://host/icingaweb/mymodule/siteB
  </code></pre>
  
  <p>I need exactly this single request in Javascript (at least the requested site).</p>
  
  <p>Unfortunately the following functions do not work:</p>
  
  <pre><code>var pathname = window.location.pathname;
  // returns (no matter which site is reloaded): "/icingaweb/mymodule/siteA"
  var url      = window.location.href;
  // returns (no matter which site is reloaded): "http://host/icingaweb/mymodule/siteA#!/icingaweb/mymodule/siteB"
  </code></pre>
  
  <p>The Icinga Web 2 parses all javascript content to a single file which is afterwards globally accessible (icinga.min.js). Custom javascript has to be put in the module.js.</p>
  
  <p><strong>module.js</strong></p>
  
  <pre><code>(function(Icinga) {
      var mymodule = function(module) {
         /**
          * The Icinga.Module instance (public/js/Icinga/module.js)
          */
         this.module = module;
         this.initialize();
         this.module.icinga.logger.info('mymodule module loaded');
      };
  
      mymodule.prototype = {
          initialize: function()
          {
              /**
               * Tell Icinga about our event handlers, these are then
               * automatically detached once Icinga is unloading
               */
              this.module.on('rendered', this.showURLs);
          },
  
          showURLs: function(event)
          {
              var pathname = window.location.pathname;
              // returns (no matter which site is reloaded): "/icingaweb/module/siteA"
              var url      = window.location.href;
              // returns (no matter which site is reloaded): "http://host/icingaweb/module/siteA#!/icingaweb/module/siteB"
          }
      };
  
      /**
       * Register this module so that Icinga knows about it
       *
       * It's important that the identifier used is the same
       * as the name of the module itself (case sensitive)
       */
      Icinga.availableModules.mymodule = mymodule;
  }(Icinga));
  </code></pre>