Hi everyone. I have this 1 project where I need to run a SSJS Function and within it, open a link in a new Window with some parameters.
The best way to do this is to use the postScript Function that belongs to the XPages view Object.
Here’s an example
Let’s say that I wanted to open an XPage in a new window and add some parameters to it:
var myparam = “Test”;
var myurl = @LeftBack(context.getUrl(),”/”) + “/myxpage.xsp?id=”+myparam;
view.postScript(“window.open(‘” + myurl + “‘)”);
As easy as that. Hope this helps
Cheers.
Hello.
I tried your solution and it works. One thing I need though is to put focus on that new window that was opened. How do I do that?
Thanks!
Hi Chad. You would need to open the new Window as an Object. Fit the following Javascript in your postScript:
view.postScript(“var tempwindow = window.open(‘” + myurl + “‘, ‘_blank’); tempwindow.focus();”);
That should do the trick.
Nice tip! Any luck getting it to work in the ApplicationLayout’s UtilityLinks? I’m using a Basic Node in the OnClick event, but it doesn’t work at all. =8( Even with “myurl” as hard coded in the code, the link isn’t activated.
Does it work for you?
Thanks!
Hi Steve. Sorry for the late reply on this.
Did you try a Container Node? Also, i know the onClick events only allow for Client Side JavaScript, which is fine because all you would do is only add the code that was inside your Post Script.
Remember if you want to use the OnClick event the href property must be empty.
Hope this helps.
Hello!
No luck. I have to use SSJS to get the link and CSJS to open the window. So, I tried each kind of node, without success. Here is the onClick SSJS in a Basic Node onClick event, with the href empty:
var nv:NotesView = database.getView(‘V_Admin’);
var nd:NotesDocument = nv.getFirstDocument();
var url = nd.getItemValueString(‘pHelpURL’);
view.postScript(“var tempwindow = window.open(‘” + url + “‘, ‘_blank’);”);
The client wants a profile document with parameters, which is how I can get the HelpURL. In the source I see the proper URL is there.
What really bothers me is that this was extremely simple pre-XPages. Even though the Application Layout is supposed to make things easier for basic applications, I don’t get the idea it is meant for complex applications. So much for Notes being a Rapid Application Development tool.
Also, did you see this article about Java hacking?: http://business.financialpost.com/2013/01/11/u-s-government-warns-of-serious-hacking-risk-in-java-software/. Are you concerned about XPage applications being hacked? Maybe I’ll just scrap XPages and do this big app the old fashioned way. =8P
Thanks!
Hi Steve,
A simple window.open(“yourURL”) in the OnClick event of your Basic Node should do the job.
What I feel in your case as the CSJS triggers before the SSJS so it might not be retrieving the URL.
Try with a hard coded url first on the OnClick event of your Basic Node and if succeeded can do some workaround for your requirement.
Hope this will help you !!!