2
votes

I am working on application and I got stuck when I wanted to open a link on new tab or window. I am using Lotus Notes Designer Release 8.5.2FP1. I have attached my piece of code.

<xp:eventHandler event="onclick" submit="true"
        refreshMode="complete">
        <xp:this.action><![CDATA[#{javascript:try{
var doc = database.getProfileDocument("frmConfiguration","");
var url = doc.getItemValueString("HeaderLink1URL");
view.postScript("var tempwindow =window.open('"  +url+"','_blank');tempwindow.focus();");
}catch(e){
}}]]></xp:this.action>
3
You can set target="_blank" in xp:link to open link in new window. But here I see you have used view.postScript, any specific reason for that? Also could you post the entire code snippet for xp:link? - Naveen
There is no specific reason to use postscript, randomly I am trying to get my code working. Please find xp:link snippet as follows: <xp:link escape="false" id="link1"> <xp:this.text>some code</xp:this.text> <xp:eventHandler event="onclick" submit="true" refreshMode="complete"> <xp:this.action><![CDATA[#{javascript:try{ var doc = database.getProfileDocument("frmConfiguration",""); var href = doc.getItemValueString("HeaderLink1URL"); view.postScript("var tempwindow = window.open('" + href + "','_blank'); tempwindow.focus();"); }catch(e){ }}]]></xp:this.action> </xp:eventHandler></xp:link> - Raj
Please add the code to your question by editing it. - Naveen

3 Answers

4
votes

Based on your updated code in comment you can simply add target="_blank" and instead of using the onClick event use the value attribute which would point to the URL to be opened. So your code would be something like this:

<xp:link escape="false" id="link1" target="_blank">
    <xp:this.text>some code</xp:this.text>
    <xp:this.value><![CDATA[#{javascript:var doc = database.getProfileDocument("frmConfiguration","");
var href = doc.getItemValueString("HeaderLink1URL");
return href;}]]></xp:this.value>
</xp:link>
1
votes

The simpliest way to do this would be something like:

<xp:text escape="false" id="newTab"><xp:this.value><![CDATA[#{javascript:return "<a href=\"http://www.google.com/\" target=\"_blank\">Google</a>";}]]></xp:this.value></xp:text>

This will open google in a addtional tab.

Update:

If you want to use a xp:link you could try:

<xp:link escape="false" id="newTab" text="test">
        <xp:this.onclick><![CDATA[var ret = window.open("http://www.google.com",'_blank');
]]></xp:this.onclick>
    </xp:link>

If you want to open the link in a seperate window or tab i recomend dont use the aktion use the onclick client side event in the option tab.

0
votes

Here is some sample code of opening a URL both client side and server side.

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">

    <xp:button value="Client Side Open Button." id="ClientSideButton">
        <xp:eventHandler event="onclick" submit="false">
            <xp:this.script><![CDATA[var href = "http://www.ibm.com";
var tempwindow = window.open(href,'_blank');
tempwindow.focus();
]]></xp:this.script>
        </xp:eventHandler>
    </xp:button>
    <xp:br></xp:br>
    <xp:br></xp:br>
    <xp:button id="serverSideButton" value="Server Side Open Button ">
        <xp:eventHandler event="onclick" submit="true"
            refreshMode="complete">
            <xp:this.action><![CDATA[#{javascript:var href = "http://www.ibm.com";
view.postScript("var tempwindow = window.open('" + href + "','_blank'); tempwindow.focus();");

}]]></xp:this.action>
        </xp:eventHandler>
    </xp:button>
</xp:view>

If this code does not work as expected, two things to check.

  1. Check that the url variable is being set correctly.

  2. Make sure you are on the latest release. window.open() didn't work as expected until 8.5.1FP2.