Reputation: 329
My iFrame looks like this:
<iframe id="iframe" name="iframe1" frameborder="0" src=""></iframe>
And my script looks like this:
<script type="text/javascript">
$(document).ready(function() {
$('#iframe').attr('src',http://google.com);
})
</script>
I've also tried putting quotes around the url:
<script type="text/javascript">
$(document).ready(function() {
$('#iframe').attr('src','http://google.com');
})
</script>
But neither is working.
What am I missing?
Upvotes: 17
Views: 69254
Reputation: 994
You're not allowed to load www.google.com in an iFrame. Try it with another url.
Load denied by X-Frame-Options: https://www.google.com/ does not permit cross-origin framing.
Upvotes: 4
Reputation: 4212
Just call the function with Iframe name and desired url
function loadIframe(iframeName, url) {
var $iframe = $('#' + iframeName);
if ( $iframe.length ) {
$iframe.attr('src',url);
return false;
}
return true;
}
Ex:
loadIframe("iframe1","http://yahoo.com");
Upvotes: 1
Reputation: 887413
If you look at the browser's error console, you'll see the real problem:
Refused to display 'https://www.google.com/' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.
Google doesn't let you do that.
Upvotes: 20
Reputation: 620
<script type="text/javascript">
$(document).ready(function() {
$('#iframe').attr('src', 'http://google.com');
})
</script>
Quotes missing on the url.
Upvotes: 9