gkreddy
gkreddy

Reputation: 15

opening a page using "onclick " event of xpages link

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>

Upvotes: 0

Views: 3118

Answers (2)

Per Henrik Lausten
Per Henrik Lausten

Reputation: 21709

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 $).

Upvotes: 1

Steve Zavocki
Steve Zavocki

Reputation: 1840

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.

Upvotes: 0

Related Questions