• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Javascript Not Running in iframe Codeigniter 3

#1
I am updating a website from CodeIgniter 2 to CodeIgniter 3 (.1.9)

We had an iframe embedded in several pages with javascript in the iframe to, among other things, put in a placeholder for telephone number and set the iframe height dynamically. This was working fine in our CodeIgniter 2 implementation, but the javascript does not seem to be running at all in the CodeIgniter 3 implementation.

The page in which the iframe is embedded (page.php) has the following code:
Code:
<iframe id="iframe_form" src="<?php echo site_url('contact/request_consultation');?>" class="span3" scrolling="no" frameborder="0"></iframe>

The javascript on the actual request_consultation page (which is in the iframe) is as follows:
Code:
<script type="text/javascript">

$(document).ready(function(){

   $(".phone").mask("(999) 999-9999",{placeholder:"_"});
   $('.error').click(function(){
       $(this).removeClass('error');
   });


   $('#iframe_form', window.parent.document).height($('body').height());  

});
//]]>
</script>

I tried moving the code into the page in which the iframe was embedded (page.php), but it did not work. It is entirely possible that I may not have referenced the iframe and/ or its elements correctly:
Code:
document.getElementById("iframe_form").(".phone").mask("(999) 999-9999",{placeholder:"_"});

I also tried giving the 
<div> on the parent page an id: 
Code:
<div id="frame_span" >

 and then referencing the id from the request_consultation page, but that did not work, either.

Code:
$('#iframe_form', window.parent.document).height($('frame_span').height());

Any suggestions would be greatly appreciated.
Reply

#2
CodeIgniter has nothing to do with the JavaScript  not running something else
has to be wrong.

The iframe is a pain in the neck and they recommend not to use them.

Not sure but maybe this will help you.

Using jQuery to Access iFrame Elements
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.