rohit
rohit

Reputation: 67

on print click how to open another page?

I have written following function to call another page when i will click print button. but when i click on print button it opens current page instead of the one which i want to call.

function printme(tripId, requestId, Ecommerce) {
        //alert("print is called");
        alert(tripId);
        alert(requestId);
        alert(Ecommerce);
        window.location.href = "ViewTripConformationPrint.cshtml?";
        window.print();

        //workaround for Chrome bug - https://code.google.com/p/chromium/issues/detail?id=141633
        if (window.stop) {
            location.reload(); //triggering unload (e.g. reloading the page) makes the print dialog appear
            window.stop(); //immediately stop reloading
        }
        return false;
    }

Upvotes: 0

Views: 68

Answers (1)

user2845090
user2845090

Reputation: 168

The problem you're having is that the code after you set window.location.href is executed immediately. The page isn't loaded and then the code continues... you code continues until the end of the function and then window.location.href is actually loaded and processed. If you see what I mean.

You could try moving your code (window.print, if window.stop, etc) into ViewTripConformationPrint.cshtml (as part of onload).

Upvotes: 1

Related Questions