简体   繁体   中英

iframe url is opening in current window instead of iframe

I have an advertiser website which I am trying to open inside an iframe. (unfortunately i cant provide you with the url) but instead of opening inside an iframe it loads up the url in the same tab.

<!DOCTYPE HTML>
<html >
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <script src="<?php echo site_url('public/scripts/core/jquery-1.11.0.min.js');?>"></script>
    <script src="<?php echo site_url("public/scripts/core/core.js");?>"></script>
</head>
<body>

<form id="iframe_form" method="POST" action="">
    <?php echo $user_id." ".$offer_id;?>




</form>
<iframe src='{{URL}}' id="qual" name="qual"></iframe>

<script type="text/javascript">
    jQuery(document).ready(function($){
        var url = "<?php echo site_url('api/check_pixel');?>";
        var offer_id = "<?php echo $offer_id;?>";
        var user_id = "<?php echo $user_id;?>";
        var intId = setInterval(
            function(){check_pixel(url,offer_id,user_id);},1000
        )
        ;

    });

</script>

Any suggestions will be helpful

Thank you in advance

Try changing the iframe src to echo site_url; inside of aPHP tag. I would heva just showed the code.

Have you tried doing something like this?

<iframe src='<?php echo $**SITEURLVARIABLE** ?>' id="qual" name="qual"></iframe>

<script type="text/javascript">
    jQuery(document).ready(function($){
        var url = "**SITEURLHERE**";
        var offer_id = "<?php echo $offer_id;?>";
        var user_id = "<?php echo $user_id;?>";
        var intId = setInterval(
            function(){check_pixel(url,offer_id,user_id);},1000
        )
        ;

    });

</script>
<iframe src='{{URL}}' id="qual" name="qual" id="myframe" sandbox="allow-forms allow-scripts allow-same-origin"></iframe>

Adding sandbox (html5 feature) worked for me. I have also added

window.addEventListener("beforeunload", function( event ) {
        event.preventDefault();
    });

just in case it does to try to load the page outside iframe.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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