Search code examples
javascriptbuttonxpageslotus-dominolotus

Lotus Notes Xpage - view.postScript("window.open()") doesn't open a new window after replacing the contained Pagename (only at a specific document)


i'm currently working on a function (started after Buttonclick) to print a document in Lotus Notes (IBM Domino Designer 9.0 Social Edition Release 9.0). I have a custom control which creates a new document to the database. After saving the document its opened in read-only-Mode. There you have a button which will redirect you to a new window where the same contents are displayed without any layouts and something else (just the Text). Now its possible to print the page with Ctrl+P. There are two differen xPages for that.

  1. Distribution.xsp
  2. DistributionPrint.xsp

First of all i'm using

path = facesContext.getExternalContext().getRequest().getRequestURL(); 

to get the current page URL. After that there is an option to replace the current Page of the path (Distribution.xsp) into DistributionPrint.xsp.

var replacePage = @RightBack(path, "/");
path = @ReplaceSubstring(path, replacePage, "DistributionPrint.xsp");

When im testing it the replacement successfully worked. After that i'm bulding a new URL for the specific document to open with the new path. Finally everything is placed into the view.postScript method:

var docid = docApplication.getDocument().getUniversalID();
view.postScript("window.open('"+path.toString() + "?documentId=" + docid + "&action=openDocument"+"')")

Now my Problem starts. At 99% of my trys the new window is opened like i said the programm to do. But there are some kind of documents where i click on the button and he doesn't open a new window and trys to open the old Distribution.xsp url. I already tested out the path he wants to open at these kind of documents by using the debugtoolbar. The result of the button click returns the completly correct URL which should be opened. I can also copy that url and paste it manually into my browser => it works! But if i want to open that URL by a buttonclick and viewPostScript nothing happens.

Has anybody expierenced the same problem like me? Maybe one of you can help me through that problem. Its really annoying that everything works finde at 99% of my documents but at some documents it doesn't work although the given url is 100 percent correct.

Thanks for everyones help!


Solution

  • Try adding you code into a javascript function on the page and call that function from your view.postscript code Or as Panu suggested add it to onCompete code