在iFrame中重定向表单提交jQuery未检测到更新的Src属性 [英] Upon Redirect of Form Submission within iFrame jQuery Not Detecting Updated Src Attribute

查看:212
本文介绍了在iFrame中重定向表单提交jQuery未检测到更新的Src属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在页面/profile/settings/index.php上有一个iframe,我不希望我的用户在更改设置时离开/profile/settings/index.php。

So I have an iframe located on the page /profile/settings/index.php, i dont want my users to move away from /profile/settings/index.php while changing their settings.

设置页面会自动加载iframe-home.php。然后我点击更改名称,它加载update.php。然后我提交表格(动作='')以便自行提交。更新名称后,它会重定向到iframe-home.php,但正如您在控制台上看到的那样,它仍然在说update.php ...这是一段关于这段内容的视频。

The settings page automatically loads iframe-home.php. i then click on change name and it loads update.php. i then submit the form (which the action='') to submit back on itself. after updating the name, it redirects to iframe-home.php, but as you can see on the console, its still saying update.php... Heres a video of what this paragraph is about.

https://www.youtube.com /watch?v=MjALpZkmgWs&feature=youtu.be

所以这里是iFrame:

So here's the iFrame:

<iframe src="iframe-home.php" id="settings-iframe" onload="onLoadHandler();" name="settings-iframe">
</iframe>

每当在此iframe中加载页面update.php时,该页面上就有一个表单。提交该表单后,在php中调用 header() Location函数,然后将iframe重定向到iframe-home.php(成功验证后等)。但是在 console.log()上没有更新iframe src属性。 console.log说我仍然在update.php而不是iframe-home.php。这是一个问题,如果我想做的事情:

Whenever the page "update.php" is loaded within this iframe, there is a form on that page. Upon submission of that form, a header() Location function is called in php and the iframe is then redirected to iframe-home.php (upon successful validation, etc etc). However upon a console.log() the iframe src attribute is not being updated. The console.log is saying that i'm still on update.php and not iframe-home.php. This is a problem if i want to do something along the lines of:

function onLoadHandler() {
    var $location = $("#settings-iframe").attr("src");
    switch($location) {
        case "iframe-home.php":
            console.log($location);
            activateHome();
        break;
        case "changepassword.php":
            console.log($location);
            activatePassword();
        break;
        case "update.php":
            console.log($location);
            activateName();
        break;

    }
}

不确定需要什么代码看到这个。我不能真正抽象代码,因为我使用了大约10种不同的类,分布在两种不同的编程语言中。

Not sure what code you need to see for this. I can't really abstract the code as i'm using about 10 different classes spread over two different programming languages.

激活函数正在改变css代码。我已经测试了这些函数,它们的工作方式是缩进的。 activateX()突出显示iFrame中加载的活动页面的导航链接。

The activate functions are changing css code. I've tested these functions and they work as indented. activateX() highlights the navigation link of the "active" page thats loaded in the iFrame.

我只想弄清楚如何强制iframe重新加载src属性在标头位置重定向,或至少获取正确的src属性。为什么iframe告诉我我在update.php上,当加载它的页面iframe-home.php ...

I'm just trying to figure out how to force the iframe to reload the src attribute upon a header location redirect, or at least grab the correct src attribute. Why is the iframe telling me that i'm on update.php, when the page thats loaded it iframe-home.php...

推荐答案

编辑: - 完整的jQuery解决方案

- Full jQuery solution

< iframe id =settings-iframename =settings-iframe> < / iframe>

$(document).ready(function() {
    $('iframe#settings-iframe').on('load', function() {
    // var location = this.contentWindow.location.href;
    var location = this.contentWindow.location.href.substr(this.contentWindow.location.href.lastIndexOf('/')+1);
    console.log('location : ', location);
    switch (location) {
        case "iframe-home.php":
        console.log(location);
        activateHome();
        break;
      case "changepassword.php":
        console.log(location);
        activatePassword();
        break;
      case "update.php":
        console.log(location);
        activateName();
        break;
    }
  });
});

旧:
试试这个: -
var $ location = this.contentWindow.location

这篇关于在iFrame中重定向表单提交jQuery未检测到更新的Src属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆