Reputation: 13347
I have a rails application that I am developing and I have inserted a some javascript code into one of my views.
<% content_for :content do %>
<div id="simulator-phone">
<%= image_tag("iPhone5.png", :id => "iPhone5") %>
<iframe id="simulator-screen"></iframe>
</div>
<%= javascript_tag do %>
$(document).ready(function () {
$('#simulator-screen').load('/simulator/LZA');
});
<% end %>
<% end %>
The problem is that the Javascript gets inserted into the output like this and therefor never executes...
<div id="simulator-phone">
<img alt="Iphone5" id="iPhone5" src="/assets/iPhone5.png">
<iframe id="simulator-screen"></iframe>
</div>
<script type="text/javascript">
//<![CDATA[
$('#simulator-screen').load('/simulator/LZA');"
//]]>
</script>
What do I need to do to make it actually execute the javascript being passed.
EDIT:
Ok, now I fixed that, but the iframe is now not loading with the contents of /simulator/LZA
. Thoughts?
Upvotes: 2
Views: 843
Reputation: 13726
I think you should be doing:
$('#simulator-screen').attr("src", '/simulator/LZA');
//or
$('#simulator-screen')[0].src = '/simulator/LZA';
//or, better yet
document.getElementById('simulator-screen').src = '/simulator/LZA';
Upvotes: 1