No luck while opening a link in new tab using XPages

妖精的绣舞 提交于 2019-12-11 02:42:45

问题


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>

回答1:


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>



回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/15765278/no-luck-while-opening-a-link-in-new-tab-using-xpages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!