Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/366.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 当xsp驻留在iframe中时隐藏控件_Javascript_Xpages_Xpages Ssjs - Fatal编程技术网

Javascript 当xsp驻留在iframe中时隐藏控件

Javascript 当xsp驻留在iframe中时隐藏控件,javascript,xpages,xpages-ssjs,Javascript,Xpages,Xpages Ssjs,我想在iframe中嵌入xpage时隐藏某些控件。我该怎么做 基于此网站上的一些建议,我尝试: 在客户端JavaScript中,我提供了: <xp:eventHandler event="onClientLoad" submit="false"> <xp:this.script><![CDATA[if (window.frameElement) { //in iframe var field = document.getElementById

我想在iframe中嵌入xpage时隐藏某些控件。我该怎么做

基于此网站上的一些建议,我尝试:

在客户端JavaScript中,我提供了:

<xp:eventHandler event="onClientLoad" submit="false">
        <xp:this.script><![CDATA[if (window.frameElement) {
  //in iframe
  var field = document.getElementById("#{id:NavBarOption}");
  alert(field.id)
  field.value = "hide";
}
else {
  //NOT in iframe
  var field = document.getElementById("#{id:NavBarOption}");
   alert(field.id)
  field.value = "";
}]]></xp:this.script>
</xp:eventHandler>

这应该设置一个inputbox控件,该控件在onchange事件中部分刷新:

<xp:inputText id="NavBarOption"
        value="${javascript:viewScope.NavBarOption}">
        <xp:this.attrs>
            <xp:attr name="type" value="hidden"></xp:attr>
        </xp:this.attrs>
        <xp:eventHandler event="onchange" submit="true"
            refreshMode="partial" refreshId="body" immediate="true"
            execMode="partial" execId="body">
        </xp:eventHandler>
    </xp:inputText>

inputbox控件绑定到范围变量。此范围变量将用于呈现属性的控件或自定义控件,例如:

<xc:ccNavBar id="ccNavBar">
            <xc:this.rendered><![CDATA[#{javascript:return true;
var hide = viewScope.showNavBar;

if (hide !=""){
    //return false;
}
else{
    //return true;
}}]]></xc:this.rendered>
        </xc:ccNavBar>


我做错了什么?

您的代码似乎有点奇怪,但可能我没有了解全部情况。让我把我的答案分成两部分:

第1节:原始任务的可能解决方案(根据控件是否是iframe的一部分隐藏控件):

只是尝试了一种非常简单的方法:

  • 构建了一个包含一个iframe的页面,该iframe的src属性正在调用 另一个xsp
  • src属性还包含一个querystring;我曾经 “?状态=帧”
  • 还构建了一个自定义控件 质询
  • 为了证明一切都按预期进行,我使用了 抄送两次:一次在iFrame调用的xsp内部,一次 直接在主页内
  • 代码如下:

    CustomControl
    ccInner
    ;具有布尔CC属性“
    isInIframe
    ”:

    “外部”xsp包含iframe定义以及自定义控件的第二个实例,再次基于urlParameter计算CC属性:

    <xp:view
        xmlns:xp="http://www.ibm.com/xsp/core"
        xmlns:xc="http://www.ibm.com/xsp/custom">
        <xp:panel
            id="iframeContainer"
            style="padding:10px;border:1px grey solid;">
            <iframe
                id="myIframe"
                frameborder="0"
                style="width:300px;height:30px;border:1px red solid;padding:5px;"
                src="testinnerifr.xsp?status=iniframe">
            </iframe>
            <xc:ccInner>
                <xc:this.isInIframe><![CDATA[#{javascript:context.getUrlParameter("status")=="iniframe"?true:false}]]></xc:this.isInIframe>
            </xc:ccInner>
        </xp:panel>
    </xp:view>
    
    
    
    对我来说效果很好:CC中的标签以预期的颜色显示预期的值

    第2节:关于代码的一些备注

  • 在基于dojo的页面中使用
    document.getElementById()
    据说效率不高;尝试使用
    dojo.byId()
    XSP.getElementById()
  • 您正在使用“
    $
    ”而不是“
    ”(“
    ${javascript:viewScope.navbroption}
    ”绑定viewScope onPageLoad指令。是否有特定原因要阻止在刷新页面时更新该值?这会导致在页面生命周期的多个阶段重新计算呈现属性,但该值仅在页面加载时更新一次。至少可以说不是很有效
  • 为什么不使用SSJS将scope变量绑定到字段,而不是像“
    {viewScope.navbroption}
    ”中那样使用EL呢
  • <xp:view
        xmlns:xp="http://www.ibm.com/xsp/core"
        xmlns:xc="http://www.ibm.com/xsp/custom">
        <xc:ccInner>
            <xc:this.isInIframe><![CDATA[#{javascript:context.getUrlParameter("status")=="iniframe"?true:false}]]></xc:this.isInIframe>
        </xc:ccInner>
    </xp:view>
    
    <xp:view
        xmlns:xp="http://www.ibm.com/xsp/core"
        xmlns:xc="http://www.ibm.com/xsp/custom">
        <xp:panel
            id="iframeContainer"
            style="padding:10px;border:1px grey solid;">
            <iframe
                id="myIframe"
                frameborder="0"
                style="width:300px;height:30px;border:1px red solid;padding:5px;"
                src="testinnerifr.xsp?status=iniframe">
            </iframe>
            <xc:ccInner>
                <xc:this.isInIframe><![CDATA[#{javascript:context.getUrlParameter("status")=="iniframe"?true:false}]]></xc:this.isInIframe>
            </xc:ccInner>
        </xp:panel>
    </xp:view>