【问题标题】:HTML after iframe neglected忽略 iframe 后的 HTML
【发布时间】:2011-11-02 01:43:47
【问题描述】:

我目前遇到了一个看起来很像 this 的问题,但是该问题的解决方案在我的情况下不起作用。

我有一个 tagx,其中有一个 iframe,我在其中使用 jQuery 将 src 属性设置为某个值,具体取决于单击的超链接。该标签由一个主要由 springform 组成的 jspx 文件嵌入。一切都很好,除了直接写在 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>

【问题讨论】:

    标签: jquery html spring iframe jstl


    【解决方案1】:

    在 iframe 中添加一些文本就可以了。

    <iframe id="ytplayer" type="text/html" width="640" height="390"
        src="http://www.youtube.com/embed/M7lc1UVf-VE?autoplay=1&origin=http://example.com"
        frameborder="0">some text</iframe>
    

    【讨论】:

      【解决方案2】:

      这发生在我的 youtube 上,嵌入在 &lt;!doctype html&gt; dom 中。

      <iframe id="ytplayer" type="text/html" width="640" height="390"
          src="http://www.youtube.com/embed/M7lc1UVf-VE?autoplay=1&origin=http://example.com"
          frameborder="0"/>
      

      诀窍是添加一个关闭的&lt;/iframe&gt; 标签,而不是一个自动关闭的标签:

      <iframe id="ytplayer" type="text/html" width="640" height="390"
          src="http://www.youtube.com/embed/M7lc1UVf-VE?autoplay=1&origin=http://example.com"
          frameborder="0"></iframe>
      

      【讨论】:

        【解决方案3】:

        您需要在 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>
        

        【讨论】:

        • 插入评论确实解决了我的问题。然而事实证明,不是浏览器不允许空标签,而是 Spring 将空标签 () 优化为它的简写版本 (),而大多数浏览器都不允许就像 iframe 标记的简写版本(以及其他一些标记)。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2022-12-07
        • 2016-10-07
        • 2018-10-27
        • 1970-01-01
        • 1970-01-01
        • 2013-07-11
        • 2021-11-07
        相关资源
        最近更新 更多