-2

I have a <div id="content">. I want to load the content from http://vietduc24h.com into my div:

<html>
<head>
<script type="text/javascript">
    $(document).ready(function()
    {
        $("#content").attr("src","http://vietduc24h.com");
    })
</script>
</head>
<body>
    <div id="content"></div>
</body>
</html

I don't want to use an iframe. How can I do this?

Lee Taylor
  • 7,761
  • 16
  • 33
  • 49
Hư Không
  • 49
  • 1
  • 1

3 Answers3

3

You need to think about CORS in this aspect. The code you need to have is:

<script type="text/javascript">
    $(document).ready(function()
    {
        $("#content").load("http://vietduc24h.com");
    })
</script>

When your domain is not inside vietduc24h.com, you might get some security exception. In order to avoid that, you can host a local proxy here. In PHP, we do this way (url.php):

<?php
    $url = file_get_contents(urlencode($_GET["url"]));
    echo $url;
?>

And in the script, you need to modify this way:

<script type="text/javascript">
    $(document).ready(function()
    {
        $("#content").load("proxy.php?url=http://vietduc24h.com");
    })
</script>
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252
0

Try this code with the jQuery Load function:

$('#content').load('http://vietduc24h.com', function() {
  alert('Load was performed.');
});

If you encounter in security issues because of the Cross-Origin-Resource-Sharing policy than you have to use a proxy in your server code.

Yair Nevet
  • 12,725
  • 14
  • 66
  • 108
-1

Try this:

  $("#content").html('<object data="http://vietduc24h.com">');

Taken from this answer.

Community
  • 1
  • 1
Simon M
  • 2,931
  • 2
  • 22
  • 37