0

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>
Community
  • 1
  • 1
gkreddy
  • 15
  • 2
  • 7
  • 2
    Have you tried calculating the URL and returning it in the value property for xp:link (as in this answer: http://stackoverflow.com/a/15767044/785061)? – Per Henrik Lausten Oct 24 '13 at 18:36
  • 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 you – gkreddy Oct 24 '13 at 20:42

2 Answers2

1

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

Per Henrik Lausten
  • 21,331
  • 3
  • 29
  • 76
  • Definitely the best way to do it. – Steve Zavocki Oct 24 '13 at 21:18
  • Hi per, Thanks for your comment. i'm trying to access viewScope variable in "this.value", when i checked server console "print" statement appears only on page load but not when i click on the link. Please see my code below. am i doing anything wrong?.Even i have tried by setting partial Refresh to the same link id "linkNewCall".`<![CDATA[#{javascript:print ("######"+viewScope.selectedTarget)}]]>` – gkreddy Oct 24 '13 at 21:32
  • When and where do you update viewScope.selectedTarget? You need to partially refresh the xp:link control from the control where you update the viewScope variable – Per Henrik Lausten Oct 25 '13 at 15:05
  • Hi Per, actually even static text was not printing. just tried printing static text print ("#####"). any code entered in "" was not printing in console during "onClick", however it was printing on "pageLoad" – gkreddy Oct 27 '13 at 13:07
0

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.

Steve Zavocki
  • 1,840
  • 4
  • 21
  • 35