Stellan Coder
Stellan Coder

Reputation: 313

iFrame with DIV and Jquery is not working

I am trying to use content of other website into my website. I tried using DIV with Jquery instead of iframe tag <iframe>

My Codes :

<head>
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js?ver=1.4'></script>

<script type='text/javascript'>
$(document).ready(function (){
$('#divframe').load('http://www.example.com');     
});
</script>
</head>
<body>
<div id="divframe"></div>
</body>

it returning no value and not showing the content of the example.com on my website. means the page is empty & blank.

Edited: I am looking for iframe solution without iframe, object, embed tag.

Please help me to get it fixed :)

Upvotes: 0

Views: 74

Answers (1)

SKJ
SKJ

Reputation: 2326

You need to use iframe tag and attr() to do this.

NOTE : you also need to be sure that the url of the website is not protected to be loaded via 3rd party site frame of iframe like youtube.com, google.com, etc.

https://en.wikipedia.org/wiki/Framekiller

$(document).ready(function (){
  $('#divframe').attr("src", "https://wikipedia.org/wiki/Main_Page");
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<iframe id="divframe" style="width:100%;height:95vh"></iframe>

Upvotes: 1

Related Questions