代码之家  ›  专栏  ›  技术社区  ›  Raj

使用XPages在新选项卡中打开链接时运气不佳

  •  2
  • Raj  · 技术社区  · 13 年前

    我正在开发应用程序,当我想在新的选项卡或窗口上打开链接时,我被卡住了。 我使用的是Lotus Notes Designer 8.5.2FP1版本。 我已经附上了我的代码。

    <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 回复  |  直到 13 年前
        1
  •  4
  •   Community Mohan Dere    9 年前

    基于您的 updated code in comment 你可以简单地添加 target="_blank" 而不是使用 onClick 事件使用 value 属性,该属性将指向要打开的URL。所以你的代码应该是这样的:

    <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
  •  1
  •   Michael Saiz    13 年前

    做到这一点最简单的方法是:

    <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>
    

    这将在一个附加选项卡中打开谷歌。

    更新:

    如果你想使用xp:链接,你可以尝试:

    <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>
    

    如果你想在单独的窗口或选项卡中打开链接,我建议不要使用选项选项卡中的onclick客户端事件。

        3
  •  0
  •   Simon O'Doherty    13 年前

    以下是一些在客户端和服务器端打开URL的示例代码。

    <?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>
    

    如果这个代码不能按预期工作,有两件事需要检查。

    1. 请检查url变量的设置是否正确。

    2. 请确保您使用的是最新版本。window.open()直到8.5.1FP2才按预期工作。