title: showModalDialog; Opens a New Window in IE
body: <p><strong>Please see update (11/27) below</strong></p>
  
  <p>I have a modal window that is launched with it's content in an iframe (ASP webforms application). We need to have the modal redirect to another page, but it cannot be within the iframe due to security reasons (Paypal processing page). In Chrome and IE standards mode, we have code that properly changes the modal's URL to the right one. However in compatibility mode, the redirect causes a new modal window to open with the correct URL. How can we stop it from opening a new window and actually redirecting?</p>
  
  <p>This is our current code:</p>
  
  <pre><code>dialog.redirect = function (location, ignoreFrames) {
          /// &lt;summary&gt;Redirects the dialog to a new URL&lt;/summary&gt;
          /// &lt;param name="location" type="String"&gt;&lt;/param&gt;
          /// &lt;param name="ignoreFrames" type="Boolean"&gt;If true, the dialog's URL will be changed instead of any parent frame URLs&lt;/param&gt;
  
          if (ignoreFrames === undefined) {
              ignoreFrames = true;
          }
  
          if (ignoreFrames === true) {
              if (window.top) {
                  //Chrome and IE9+
                  window.top.document.location.replace(location);
              } else {
                  //This was a supposed fix but it did not change the outcome
                  //&lt;IE8 and compat mode
                  var redirectLink = document.createElement("a");
                  redirectLink.href = location;
                  document.body.appendChild(redirectLink);
                  redirectLink.click();
              }
          } else {
              window.document.location.replace(location);
          }
      };
  </code></pre>
  
  <p><strong>Update 11/27, with example of issue:</strong> </p>
  
  <p><strong><a href="http://plnkr.co/edit/IJ3xKlYKIYcyAb22mJdy?p=preview" rel="nofollow">Interactive Example</a></strong> (Requires IE10+ or any good browser)  </p>
  
  <p>The following is an example of the issue, with everything set up how we have it. When the modal is in IE compatibility mode, it opens a new window instead of redirecting the modal. Fixing the page to be in compatibility mode is not an easy process, as our application relies on compatibility mode and the outer modal  page is used extensively everywhere. Viewing the page (main.html) in FireFox (Chrome has that domain security issue), it works as expected; the modal is completely redirected to the new page.</p>
  
  <p><em>main.html</em></p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;&lt;/head&gt;
  &lt;body&gt;
      &lt;a href="javascript:window.showModalDialog('modal.html', self, 'status:no;resizable:yes;help:no;scroll:no;width:1000;height:600')"&gt;Open Modal&lt;/a&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><em>modal.html</em> </p>
  
  <pre><code>&lt;!--[if lt IE 7]&gt; &lt;html class="lt-ie9 lt-ie8 lt-ie7"&gt; &lt;![endif]--&gt; 
  &lt;!--[if IE 7]&gt;    &lt;html class="lt-ie9 lt-ie8"&gt; &lt;![endif]--&gt; 
  &lt;!--[if IE 8]&gt;    &lt;html class="lt-ie9"&gt; &lt;![endif]--&gt; 
  &lt;!--[if gt IE 8]&gt;&lt;!--&gt; &lt;html class=""&gt; &lt;!--&lt;![endif]--&gt;
      &lt;head&gt;
          &lt;title id="tagTitle"&gt;&lt;/title&gt;
      &lt;/head&gt;
      &lt;body style="margin:0px"&gt;     
          &lt;form name="Form1" method="post" action="" id="Form1"&gt;
              &lt;strong&gt;modal.html&lt;/strong&gt;&lt;br /&gt;
              &lt;iframe frameborder="1" src="frame.html" scrolling="yes"&gt;&lt;/iframe&gt;
          &lt;/form&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><em>frame.html</em></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;!--[if lt IE 7 ]&gt; &lt;html class="ie6" xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;![endif]--&gt;
  &lt;!--[if IE 7 ]&gt;    &lt;html class="ie7" xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;![endif]--&gt;
  &lt;!--[if IE 8 ]&gt;    &lt;html class="ie8" xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;![endif]--&gt;
  &lt;!--[if IE 9 ]&gt;    &lt;html class="ie9" xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;![endif]--&gt;
  &lt;!--[if (gt IE 9)|!(IE)]&gt;&lt;!--&gt;
  &lt;html class="" xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;!--&lt;![endif]--&gt;
  &lt;head&gt;
      &lt;meta charset="utf-8" /&gt;
      &lt;meta name="viewport" content="width=device-width" /&gt;
      &lt;meta http-equiv="X-UA-Compatible" content="IE=edge" /&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;strong&gt;frame.html&lt;/strong&gt;&lt;br /&gt;
  &lt;a href="javascript:void(0)" onclick="redirectToCart();" title="My Cart"&gt;Trigger Redirect&lt;/a&gt;
  
  &lt;script type="text/javascript"&gt;
      var redirect = function (location, ignoreFrames) {
          /// &lt;summary&gt;Redirects the dialog to a new URL&lt;/summary&gt;
          /// &lt;param name="location" type="String"&gt;&lt;/param&gt;
          /// &lt;param name="ignoreFrames" type="Boolean"&gt;If true, the dialog's URL will be changed instead of any parent frame URLs&lt;/param&gt;
  
          if (ignoreFrames === undefined) {
              ignoreFrames = true;
          }
  
          if (ignoreFrames === true) {
              window.top.document.location.replace(location); //IE will create a new window at this point, instead of changing the modal's URL
          } else {
              window.document.location.replace(location);
          }
      };
  
      function redirectToCart() {
          redirect('anotherpage.html', true); //Change this to false to see just the inner frame's URL change
      }
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><em>anotherpage.html</em> </p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
      &lt;strong&gt;anotherpage.html&lt;/strong&gt;&lt;br /&gt;
      Success
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>