0

From my web page i have a print icon. On Clicking the icon i open a pop up page "Print_content.aspx"

I pass the querystring to the popup page ?print = URL of parent page and name of the DIV to fetch in parent page "#subcontent" and will load the content inside div subcontent (parent page) to div siteloader which is in my popup page.

This works perfectly with Mozilla and Chrome. But not with IE

Jquery in Popup page :

    var value = window.location.search;   
    $(document).ready(function () {
        $("#siteloader").load(value.replace("?print=", "") + " #subcontent");
    });  
</script>  

Whole markup of Print_content.aspx

    <script type="text/javascript" src="../Scripts/jquery-1.7.2.min.js"></script>

    <link href="../print.css" rel="stylesheet" type="text/css" />
    <title></title>
</head>
<body> 
    <table>
        <tr>
            <td>
                <div id="logo">
                </div>
            </td>
        </tr>
        <tr>
            <td align="center">
                <a runat="server" id="img_Print" onclick="window.print()">
                    <img id="Img1" runat="server" src="/image/btn_print.gif" /></a>

            </td>
        </tr>
        <tr>
        <td align="left">
          <div id="siteloader">
                </div>
        </td>
        </tr>
    </table>


    <script type="text/javascript">

        var value = window.location.search;   
        $(document).ready(function () {
            $("#siteloader").load(value.replace("?print=", "") + " #subcontent");
        });  
    </script>  

   <div id="div-overlay" style="position: absolute; top:130px; height: 100%; width: 100%; z-index: 200;  opacity: 0.0;background-color:Gray;"> </div> 
</body>
</html> 
Anuya
  • 8,082
  • 49
  • 137
  • 222

1 Answers1

0

Did you mean to use var value = window.location.href instead?

Another way to print contents from PARENT page to POPUP page could be such as the following:

$("a.doPrint").click(function(e) {
  e.preventDefault();
  var printSource = $("#myElementToPrint");
  var printWindow = window.open("", "printWindow", "width=700,height=400,location=no,menubar=yes,resizable=no,scrollbars=yes,status=no,titlebar=no,toolbar=no");
  if(!printWindow) alert("Please enable popups to access this feature.");
  else {
    printWindow.onload = function() {
      setTimeout(function() {
        if (printWindow.screenX === 0) {
          alert("Please enable popups to access this feature.");
        }
      }, 0);
    };
    printWindow.document.write('<html><head><title>Printing Page</title></head><body>' + printSource.html() + '</body></html>');
    printWindow.print();
  }
  return false;
});
Rob W
  • 9,134
  • 1
  • 30
  • 50
  • No, window.location.search is to search for the div in parent page with the query string value passed. There are two values passed to the pop up page via querystring. Name of the parent page and div id in the parent page to be shown in pop up page – Anuya Jun 05 '13 at 03:39
  • Once I fetch the DIV contents of parent page, i replace it with the DIV in the pop up page. My question is why it does not work for IE alone ? – Anuya Jun 05 '13 at 03:40
  • `window.location.search` is everything after, and including, the `?` in the GET request. For example, "http://google.com/search?q=test&hl=en" - `window.location.search` would yield "?q=test&hl=en"... Which is not a valid URL on its own. – Rob W Jun 05 '13 at 04:16
  • With that said, perhaps you can prepend the requested page with `document.referrer` and have it show `document.referrer + value.replace("?print=", "") + " #subcontent"` – Rob W Jun 05 '13 at 04:18
  • Updated my answer with an example. – Rob W Jun 05 '13 at 04:21
  • I replace with document.referrer and it still dosent work in IE. But other browsers work. On IE i see a div in gray color through out the page. Is the issue due to
    ???
    – Anuya Jun 05 '13 at 04:25
  • It's possible that the other browsers know to check the referrer (since you're using a relative path). Either that or I'm not understanding this at all. – Rob W Jun 05 '13 at 04:45
  • May be due to the load function which will not work well in IE ? As per my search in google. http://stackoverflow.com/questions/1061525/jquerys-load-not-working-in-ie-but-fine-in-firefox-chrome-and-safari – Anuya Jun 05 '13 at 06:52