Javascript页面加载重定向父框架

时间:2012-10-18 13:45:27

标签: php javascript redirect iframe parent

我有一个用户登录的iframe弹出窗口。问题是当他们登录重定向时,会在iframe中加载页面而不是父元素。

我知道我需要在某处插入此代码才能使其正常工作:

window.top.location.href = "http://www.site.com"; 

重定向单元的代码如下:

function login_redirect( $redirect_to, $request, $user ) {
    global $theme_my_login;

    // Determine the correct referer
    if ( !$http_referer = wp_get_original_referer() )
        $http_referer = wp_get_referer();

    // Remove some arguments that may be present and shouldn't be
    $http_referer = remove_query_arg( array( 'instance', 'action', 'checkemail', 'error', 'loggedout', 'registered', 'redirect_to', 'updated', 'key', '_wpnonce', 'reauth' ), $http_referer );

    // Make sure $user object exists and is a WP_User instance
    if ( !is_wp_error( $user ) && is_a( $user, 'WP_User' ) ) {
        if ( is_multisite() && empty( $user->roles ) ) {
            $user->roles = array( 'subscriber' );
        }
        $redirection = array( 'login_type' => 'default' );
        foreach ( (array) $user->roles as $role ) {
            if ( $theme_my_login->options->get_option( array( 'redirection', $role ) ) ) {
                $redirection = $theme_my_login->options->get_option( array( 'redirection', $role ) );
                break;
            }
        }
        if ( 'referer' == $redirection['login_type'] ) {
            // Send 'em back to the referer
            $redirect_to = $http_referer;
        } elseif ( 'custom' == $redirection['login_type'] ) {
            // Send 'em to the specified URL
            $redirect_to = $redirection['login_url'];
            // Allow a few user specific variables
            $replace = array( '%user_id%' => $user->ID, '%user_login%' => $user->user_login );
            $redirect_to = str_replace( array_keys( $replace ), array_values( $replace ), $redirect_to );
        }
    }

    // If a redirect is requested, it takes precedence
    if ( !empty( $request ) && admin_url() != $request && admin_url( 'profile.php' ) != $request )
        $redirect_to = $request;

    // Make sure $redirect_to isn't empty
    if ( empty( $redirect_to ) )
        $redirect_to = get_option( 'home' );

    return $redirect_to;
}

0 个答案:

没有答案