I have a simple Web Browser Control that displays a local webpage and that webpage has records and a print function , but whenever i click on the print button inside webpage i being redirected to IE and the print Dialog pops up , what i want is to disable being redirected to any other browser and display the print dialog from my web browser control.
I have searched a lot for a solution but the only thing that kind of logic accepted is :
private void webBrowser1_NewWindow(object sender, CancelEventArgs e)
{
e.Cancel = true;
}
But didn`t work…..
Here is the JavaSCript Function :
<script type="text/javascript">
function printDiv(printDiv)
{
//calledFromJSHandlerFunction(document.getElementById(printDiv).innerHTML);
var w = window.open("about:blank");
w.document.write(document.getElementById(printDiv).innerHTML);
w.print();
w.close();
}
Finally hope you guys help me.
Plugging your javascript into my JS-to-English translator…
The Print command only works on window objects. So if you do not want to print the entire page, and you do not want to create a new window… you will have to create a new CSS and reference it in your HTML. This new CSS will have the
media="print"attribute, and will define all elements as non-visible (egvisibility: hidden;) except for the div you want printed.Alternately you might be able to acheive the same thing by using an
IFRAME.