【问题标题】:link not loading in iframe after the first time第一次后链接未在 iframe 中加载
【发布时间】:2022-01-28 02:04:58
【问题描述】:

我刚开始使用 iframe,遇到了一个我不太了解的问题。我有一个导航栏和一个 iframe。一旦我单击一个链接“搜索”,该链接确实会加载到 iframe 中,我可以在那里工作,但如果我再次单击“搜索”或“表单”,链接会在另一个选项卡中打开。我怎样才能阻止这种情况发生并重新加载到 iframe 中?

<div id="container">
        <ul id="leftnav">
            <li>
                <a href="search.php" target="admin_frame">Search!</a>
            </li>
            <li>                    
                <a href="form.php" target="admin_frame">Form</a>
            </li>

        </ul>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;



        <div id="iframe">
        <iframe  id ="admin_frame" name="admin_frame" width="99%" height= "100%"></iframe>
        </div>



    </div>

搜索.php

此页面允许用户上传名称列表,然后在 parse_csv.php 中对其进行解析。将名称列表放入数组后,我使用 javascript API 获取信息,然后使用 AJAX 将其发送到 php。我能够得到确认,一切正常。这一切都发生在 iframe 中,所以当我单击“搜索”上传另一个列表时,它会在另一个窗口中打开。

<body>
<div class="left">
    <h3>Upload list.</h3>   
        <h4 style="color:red">File to upload must be <a href="" onclick="openWin()">.csv</a></h4>
        <form action="parse_csv.php" method = "POST" enctype= "multipart/form-data">
            <input type="file" name="list" /><br/>
            <input type="submit" value="Upload" /><br/>
        </form>
</div>



</body>

【问题讨论】:

  • “搜索”链接的点击事件中是否有任何代码?
  • 你是否在每次点击搜索时都设置 iframe 的 'src' 属性?
  • @JasonLokiSmith 如果我最初不想要 iframe 中的任何内容,我还需要“src”吗?它会是一个空白的html页面吗?我试过了,我仍然遇到同样的问题。
  • @BishnuPaudel Search.php 确实包含上传文件的代码。我将编辑添加它。

标签: php html css


【解决方案1】:

sandbox="allow-same-origin"

使用这个属性就不会再发生了

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-10
    相关资源
    最近更新 更多