【问题标题】:iframe: Redirect to externel urliframe:重定向到外部网址
【发布时间】:2015-09-30 10:42:14
【问题描述】:

我正在Yii 的网站上工作。情况是这样的。在网站中,users 提供了一段代码,如下所示:

<iframe height="700" allowTransparency="true" frameborder="0" scrolling="no" style="width:100%;border:none" src="http://djoneclick.com/index.php?r=webservice/form&id=6b720ff1c3cdce6c278e784a3228fd9fadc6d864" title="" >
<a href="/index.php?r=webservice/form&id=6b720ff1c3cdce6c278e784a3228fd9fadc6d864" title="">

</a>
</iframe>

User 可以将其嵌入到任何他们想要的地方,并接受目标受众的询问。这个iframe 包括src,它是一个form,它提交给Yii 中的controller。在controller 中,当有一个特定的if 条件true 时,它redirects 到外部url。它会重定向,但url(它被重定向到的)的内容显示在iframe 中。我想要的实际上是redirect 到那个url。 为此,我在R&amp;D 上花费了数小时,但找不到任何解决方案。有什么帮助吗?

【问题讨论】:

  • 也许这对你有帮助:stackoverflow.com/questions/580669/…
  • 这个声明要使用这个,window.top.location.href = "http://www.example.com"; 但我不知道,在我的代码中哪里使用这个?
  • 您在提交表单时是否在进行 ajax 调用?
  • 不,表单正在像普通表单一样提交。
  • 使用 Ajax 提交表单,一旦收到来自 ajax 的响应,请执行 window.top.location.href = "http://www.yoursite.com";

标签: javascript php redirect iframe yii


【解决方案1】:

controller 中的条件为真后尝试此操作:

echo "<script>";
echo "this.parent.location.href = '$externel_url'";
echo "</script>";

【讨论】:

  • 哦,太好了,像魅力一样工作! (y)
【解决方案2】:
$("#idForm").submit(function() {

var url = "path/to/your/script.php"; // the script where you handle the form input.

$.ajax({
       type: "POST",
       url: url,
       data: $("#idForm").serialize(), // serializes the form's elements.
       success: function(data)
       {
           window.top.location.href = "http://www.yoursite.com";
       }
     });

      return false; // avoid to execute the actual submit of the form.
});

【讨论】:

    猜你喜欢
    • 2023-03-03
    • 1970-01-01
    • 2017-10-07
    • 2022-08-20
    • 2015-10-04
    • 2013-09-09
    • 2019-03-17
    • 2020-05-13
    • 2021-10-21
    相关资源
    最近更新 更多