Raj
Raj

Reputation: 374

No luck while opening a link in new tab using XPages

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>

Upvotes: 2

Views: 3647

Answers (3)

Naveen
Naveen

Reputation: 6936

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>

Upvotes: 4

Michael Saiz
Michael Saiz

Reputation: 1640

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.

Upvotes: 1

Simon O&#39;Doherty
Simon O&#39;Doherty

Reputation: 9359

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.

Upvotes: 0

Related Questions