cancel
Showing results for 
Search instead for 
Did you mean: 

Calling a view in a separate window to print it

Carola1
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello

BSP with MVC:

In my main view there is a print button, which should call another view, which I want to print with standard

print functionality.

How is the syntax to call a view which is part of the same BSP-Application in a Separate window?

Thanks and Kind regards.

Carola

Accepted Solutions (1)

Accepted Solutions (1)

maximilian_schaufler
Active Contributor
0 Kudos

Yes, Rainer is right.

A "view" actually is only a server side concept, the client does not know or care about that - it only recognises whole HTML pages as a response to a previous request.

So you might want to create a special controller which only displays this one view, and use this controller as target URL for the popup.

Max

Carola1
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello Max.

thanks for your answer.

Now I have created a new controller (print.do) that calls one view (print.htm).

the button to open the new window is placed on controller

page1.do on the view header.htm.

Could you give me some more help concerning the syntax and the place to call the print.htm in a separate view.

Kind regards.

Carola

maximilian_schaufler
Active Contributor
0 Kudos

Hi Carola,

you can do it in various ways, here is one of them:

Place this code before the button element:

<script type="text/javascript">
function PrintWindowOpen() {
  window_parameters = 'hotkeys=no,location=no,menubar=yes,toolbar=no,status=yes,resizable=yes,top=0,left=0,'
                    + 'width=' + screen.availWidth + ',height=' + screen.availHeight;
  window_location = 'print.do';
  myPrintWindow = window.open(window_location,'myPrintWindow',window_parameters);
  myPrintWindow.focus();
}
</script>

And do this for the button element you want to use for opening the print window:

<htmlb:button ...
  onClientClick = "PrintWindowOpen();"
  ... />

The javascript variable <b>window_parameters</b> is a string containing parameter to control the window that will get opened, for a full listing of what you can use see this page:

<a href="http://www.w3schools.com/htmldom/dom_obj_window.asp">HTML DOM Window Object on www.w3schools.com</a>;

Cheers,

Max

-


Message was edited by: Brian McKellar

Fixed the code

From: onClientClick = "javascript:PrintWindowOpen();"

To: onClientClick = "PrintWindowOpen();"

It is not required, nor good, to set the JavaScript: protocol, as this is implicitly done already in browser. Otherwise, perfect example!

Answers (1)

Answers (1)

rainer_liebisch
Contributor
0 Kudos

Hi Carola,

a new window needs a new HTML page. Now you can call either a page with flow logic by clicking on the print button or you call a new controller which calls a main view. Both can be done with

window.open('myUrl.htm', _blank, ...);

in the OnClick of the button.

Regards,

Rainer