简体   繁体   English

使用jQuery将页面重定向到iframe

[英]redirect a page into an iframe using jQuery

I have a job board website/script that uses 3rd party content that I collect from an XML feed. 我有一个职位委员会网站/脚本,该网站使用我从XML提要中收集的第三方内容。 When the applicant hits the apply button for a job, an iframe opens but they are redirected to another website to apply. 当申请人点击求职按钮时,iframe会打开,但会重定向到另一个网站进行申请。 I would like the domain in the iframe to stay the same as my domain so they would appear to be applying on my domain. 我希望iframe中的域与我的域保持相同,这样它们似乎可以应用于我的域。 I tried changing: 我尝试更改:

window.location = '<?php echo jb_escape_html($data['app_url']);?>';

To

$('iframe').attr('src','<?php echo jb_escape_html($data['app_url']);?>';

But the iframe does not load the redirected url and gives a blank page as output. 但是iframe不会加载重定向的网址,并提供空白页作为输出。 please help me overcome this hurdle. 请帮助我克服这一障碍。

Here is the original code 这是原始代码

// redirect the user to a custom URL

    jb_app_redirect_script($data);



} elseif (JB_ONLINE_APP_SIGN_IN!='YES') {

    // users can apply without logging in

    jb_app_redirect_script($data);

}


}

function jb_app_redirect_script(&$data) {

    ?>

    <script type="text/javascript">
        function js_redirect() {
            // //parent.window.location = 'http://www.cnn.com/';
            window.location = '<?php echo jb_escape_html($data['app_url']);?>';
          }
          window.onload = js_redirect;
    </script>

    <?php


}

$JBMarkup->body_close();

$JBMarkup->markup_close();

If you don't have control over the 3rd party site, you will be hit with the cross-domain policy when attempting to interact with that iFrame. 如果您无法控制第三方网站,则在尝试与该iFrame进行交互时会遇到跨域策略。

If you're trying to circumvent this by artificially altering the domain, it won't work. 如果您试图通过人为更改域来规避此问题,那么它将无法正常工作。 However, if you do have control over the iFramed site, this is a good post for communicating between the two: Cross domain iframe issue . 但是,如果您确实可以控制iFrame网站,那么这是在两者之间进行交流的好地方: 跨域iframe问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM