iframe 的链接在父窗口中打开

Posted

技术标签:

【中文标题】iframe 的链接在父窗口中打开【英文标题】:Link of iframe open in the parent window 【发布时间】:2018-02-21 12:30:06 【问题描述】:

我是这里的新手,我想通过单击 iframe 上的按钮打开一个链接,以便在父页面中打开。这是我使用的代码,目前它会在新窗口中打开链接。

<html>
<body>
    <form>
      <div class="imgcontainer">
        <img src="http://www.khadimtours.com/images/kaba-box1.png"  class="avatar">
      </div>

      <div class="container">
        <label class="sansserif"><b>Username</b></label>
        <input type="text" placeholder="Enter Username" name="userid" required>

        <label class="sansserif"><b>Password</b></label>
        <input type="password" placeholder="Enter Password" name="pswrd" required>
        <button type="button" onclick="check(this.form)">Login</button>    

      </div>

      <div class="container" style="background-color:#f1f1f1">
        <button type="button" class="cancelbtn" onclick="reset(this.form)">Cancel</button>    
      </div>    
    </form>

    <script language="javascript">
        function check(form)/*function to check userid & password*/ 
         /*the following code checkes whether the entered userid and password are matching*/
         if (form.userid.value == "user1" && form.pswrd.value == "user1") 
            window.open('http://user1') /*opens the target page while Id & password matches*/
          else if (form.userid.value == "user2" && form.pswrd.value == "user2") 
            window.open('http://user2') /*opens the target page while Id & password matches*/
          else 
            alert("Invalid Password or Username") /*displays error message*/
          
    
        function reset(form) 
            document.getElementById().reset();
    
    </script>
</body>

注意:我在 wix 上设计一个网站,并使用 wix html/iframe 创建登录表单

谢谢

【问题讨论】:

parent.open .... 等等? 您能否提供您的 HTML 结构,以帮助我们了解应该在哪里打开。 我尝试将它从 window.open 更改为 parent.open,但仍然无法正常工作 嗨 Aydin,我已经提供了 HTML 代码 【参考方案1】:

在window.open(URL, '_parent')中添加可选的第二个参数为'_parent'; 请以真实网址为准。

【讨论】:

您好,Jay,感谢您的回复。但它不起作用。我放了第二个参数,当我点击它时按钮没有做任何事情。 嗨,Jay,是的,我将 URL 更改为真实的 URL,但仍然无法正常工作。顺便说一句,我正在设计一个关于 wix 的网站并使用 wix html/iframe 创建登录表单

以上是关于iframe 的链接在父窗口中打开的主要内容,如果未能解决你的问题,请参考以下文章

如果通过点击JS,让新页面在父窗口打开.

从 iframe 打开一个模态窗口到父窗口

在iframe窗体内 获取父级的元素;;在父窗口中获取iframe中的元素

jquery,iframe,如何在父窗口监听,子窗口发生改变时,父窗口获取子窗口的值

在父窗口中访问 iFrame 的 cookie

在父窗口的上下文中运行脚本