0
votes

i'm having hard time in opening a xpage in new tab. i have tried many ways as suggested in the below link No luck while opening a link in new tab using XPages but no luck. i couldn't use "link type" as i'm dynamically generating the url by passing parent document unid, document unid, frompage etc. that is the reason i'm using "onClick" event of the link. Any help would be greatly appreciated. Thanks in advance below is my code.

 <?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:link escape="true" text="New Call"id="linkNewCall">
<xp:eventHandler event="onclick" submit="true" refreshMode="partial" refreshId="linkNewCall">
<xp:this.action><![CDATA[#{javascript:var url="www.google.com"
//view.postScript("window.open('" + url + "')");
view.postScript("var tempwindow = window.open('" + url + "','_blank'); tempwindow.focus();")}]]></xp:this.action>
</xp:eventHandler></xp:link>
</xp:view>
2
Have you tried calculating the URL and returning it in the value property for xp:link (as in this answer: stackoverflow.com/a/15767044/785061)?Per Henrik Lausten
Hi Per, As mentioned in my question i cannot use "link Type. i think this.value (href) will be set "on page load". However this works if i have a static url. Thank yougkreddy

2 Answers

1
votes

You can calculate the URL server-side and then use the target property. Here I am using your simple example but you can do all sorts of calculations:

<xp:link escape="false" id="linkNewCall" text="New Call" target="_blank">
    <xp:this.value><![CDATA[#{javascript:
        var href = "http://www.google.com";
        return href;
    }]]></xp:this.value>
</xp:link>

You can change the value calculation to "Compute on page load" too (just change # to $).

0
votes

Since you are using Serverside Javascript, you can use it to open the new window. There is no need to use view.postScript to do the same thing.

There are a couple ways you can do it. One way is to look into facesContext.getExternalContext() ...

view.postScript sometimes doesn't work in certain contexts, and when it doesn't work it often doesn't return an error it just doesn't do anything.

EDIT: The link onclick event supports clientside javascript as well, if you really are comfortable using that, then put your code there. The default tab opens to serverside, you have to click "client" to add the code.