2011-08-23 91 views
4

我目前被困在一个第一手很像this的问题上,但是这个问题的解决方案在我的情况下不起作用。iframe忽略后的HTML

我有一个tagx,其中我有一个iframe,我在其中使用jQuery将src属性设置为某个值,具体取决于所单击的超链接。标签由jspx文件嵌入,大部分由springform组成。除了直接在iframe下面编写的代码不会被浏览器显示(在Firefox和Chrome中测试,不确定是否适用于其他浏览器),一切都可以很好地工作。甚至没有显示在标签正下方的jspx中编写的代码(将标签嵌入到iframe中)。

containerCreator.jspx:

<div xmlns:c="http://java.sun.com/jsp/jstl/core" 
    xmlns:form="http://www.springframework.org/tags/form" 
    xmlns:jsp="http://java.sun.com/JSP/Page" 
    xmlns:roo="urn:jsptagdir:/WEB-INF/tags" 
    xmlns:olo_elem="urn:jsptagdir:/WEB-INF/tags/olo/admin/element" 
    xmlns:spring="http://www.springframework.org/tags" 
    id="elementen_base" 
    version="2.0"> 

    <spring:url value="/admin/element/saveContainerElementBean" var="save"/> 
    <form:form action="${save}" method="POST" modelAttribute="containerElementBean"> 
     <input type="submit" value="sla op"/> 
     <olo_elem:containerCreator path="${path}" containerId="${id}"/> 
     <p>I'm not visible</p> 
    </form:form> 
</div> 

containerCreator.tagx:

<jsp:root xmlns:c="http://java.sun.com/jsp/jstl/core" 
    xmlns:fn="http://java.sun.com/jsp/jstl/functions" 
    xmlns:jsp="http://java.sun.com/JSP/Page" 
    xmlns:form="http://www.springframework.org/tags/form" 
    xmlns:olo_elem="urn:jsptagdir:/WEB-INF/tags/olo/admin/element" 
    xmlns:spring="http://www.springframework.org/tags" version="2.0"> 

    <jsp:directive.attribute name="containerId" type="java.lang.Long" required="false" description="id van de container die wordt bevat, null indien nog geen container is gebonden" /> 
    <jsp:directive.attribute name="path"  type="java.lang.String" required="false" description="pad waarin het id van een nieuw containerelement wordt gezet"/> 

    <spring:url value="/admin/element/editContainer/${containerId}" var="existingLink" /> 
    <spring:url value="/admin/element/newContainer"     var="newLink" /> 

    <script type="text/javascript"> 
     function openExisting(){ 
      $('#editor').attr('src', '${existingLink}'); 
      $("#editor").show(); 
     } 

     function openNew(){ 
      $('#editor').attr('src', '${newLink}'); 
      $("#editor").show(); 
     } 

     $(document).ready(function(){ 
      $("#editor").hide(); 
     }); 
    </script> 

    <c:choose> 
     <c:when test="${not empty id}"> 
      <a onclick="javascript: openExisting()">Bewerk ContainerElement</a> 
     </c:when> 
     <c:otherwise> 
      <c:choose> 
       <c:when test="${not empty path}"> 
        <input type="hidden" name="${path}" id="path" value=""/> 
        <a onclick="javascript: openNew()">Maak ContainerElement</a> 
       </c:when> 
       <c:otherwise> 
        Error: Geef containerId of tag op! 
       </c:otherwise> 
      </c:choose> 
     </c:otherwise> 
    </c:choose> 

    <iframe id="editor" style='width: 800px; height: 800px' name="iframeId" frameborder="0"> </iframe> 
    <p>I'm not visible</p> 
</jsp:root> 

回答

5

你需要做的是插入的iframe标记之间的注释。有些浏览器不允许空标签。在这些标签中插入注释可能会解决您的问题。看下面的例子:

<iframe id="editor" style='width: 800px; height: 800px' name="iframeId" frameborder="0"><!-- //required for browser compatibility --></iframe> 
    <p>I am visible!</p> 
</jsp:root> 
+1

插入评论确实解决了我的问题。但事实证明,它不是浏览器不允许空标签,而是Spring将空标签(