【问题标题】:Links within iframe to open in parent windowiframe 中的链接在父窗口中打开
【发布时间】:2013-07-30 22:51:44
【问题描述】:

我正在使用 html 表单向特定 URL 提交信息,该 URL 在我的域中的一个网站页面的 iframe 中加载。 html 表单输入之一是在我提交表单时将发布在 iframed 页面中的 URL。但是,当我单击链接(我在 html 表单中指定 URL 的链接)时,我需要它跳出 iframe,并加载到父窗口(iframe 当前所在的窗口)。 这是我的表单,您可以看到“producturl”的输入……这就是我遇到问题的地方……

<form action="http://ww#.aitsafe.com/cf/add.cfm" method="post"> 
<input type="hidden" name="userid" value="#######">
<input type="hidden" name="nocart"> 
<input type="hidden" name="return" value="www.fruitfulfarm.net/cart_2.html"> 
<input type="hidden" name="producturl" value=<a href="www.fruitfulfarm.net" target="_top"</a>
<input type="hidden" name="product" value="Product">
<input type="hidden" name="price" value="49.95">
<input class="rounded" type="submit" name="Submit" value="Add To Cart">
</form>

有人可以告诉我一种方法,通过使用“producturl”语法中的特定目标/值代码来让 URL 脱离 iframe 吗?

【问题讨论】:

  • 目标应该是_parent,如果它在一个框架中
  • 仍然没有突破 iframe,当您单击 iframe 中的链接时,它也会出现错误:未找到 - 请求的 URL /cf/www.fruitfulfarm.net在这个服务器上没找到。我不知道这是为什么。?
  • 这不是格式正确的 html。第 5 行无法理解。
  • 需要更改哪些内容才能使其格式正确?我正在试验第 5 行。
  • 我认为使用 javascript 是可能的。我可能会假设您的 iframe 会执行一些服务器端技巧。因此,您可以只传递要重定向到的页面的 url(没有 href 等)并使用 javascript 重新加载(smth. like window.top.location.href)。

标签: html forms url iframe breakout


【解决方案1】:

我会使用一些 JavaScript。

this.top.location = "www.fruitfulfarm.net";

看看css-tricks

【讨论】:

  • 如何实现这个?我在表单输入中输入了什么?我需要对 iframe 进行编码做什么?请提供一些细节,因为我不擅长编码。
  • 尝试在页面顶部添加一些 javascript 'code'var link = document.getElementById('my-link'); link.onclick = function() { this.top.lcation = link.href return false; }
  • 你使用了我的建议吗?还是您以其他方式做到的?
  • 你必须把这段代码 if (top != parent) { top.location.href = parent.location.href; } 在一个新的 javascript 文件中,将其命名为 breakiframe.js 并上传到您的服务器,然后使用 Hope 在您的网页头部引用它别人觉得这很有用!
猜你喜欢
  • 2018-02-21
  • 2017-07-19
  • 1970-01-01
  • 1970-01-01
  • 2010-11-05
  • 2011-06-02
相关资源
最近更新 更多