2

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>
Raj
  • 264
  • 1
  • 3
  • 18
  • 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 Apr 02 '13 at 13:38
  • There is no specific reason to use postscript, randomly I am trying to get my code working. Please find xp:link snippet as follows: some code <![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){ }}]]> – Raj Apr 02 '13 at 14:29
  • 1
    Please add the code to your question by editing it. – Naveen Apr 02 '13 at 14:41

3 Answers3

4

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>
Community
  • 1
  • 1
Naveen
  • 6,786
  • 10
  • 37
  • 85
1

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.

Michael Saiz
  • 1,640
  • 12
  • 20
  • thank you for your quick response. How to include it in xp link ? – Raj Apr 02 '13 at 14:23
  • Ok. But I need to include data from back end document. – Raj Apr 02 '13 at 14:50
  • No problem where you need it, but i would use Naveen's solution. Wow i overlooked the target propertie.. or is this one new in 8.5.3? "gues i am just blind" =) – Michael Saiz Apr 02 '13 at 14:52
  • I need to get url from profile document. I am new to x pages, is there any function which can pull data from SSJS to CSJS? – Raj Apr 02 '13 at 14:54
  • Hmm.. are you trying to open the document from a viewpanel? In that case there would be a better solution. – Michael Saiz Apr 02 '13 at 15:00
0

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.

Simon O'Doherty
  • 9,259
  • 3
  • 26
  • 54