5

I want to load the page from the external url in the div without IFrame or object, I need the alternate way for it. Can any one help me out.

It works only when i use Iframe or object.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>Test page</title>
    <script src="https://code.jquery.com/jquery-1.7.2.min.js"></script>
    <script>
      $(document).ready(function() { 
        $("#siteloader").load( "https://www.w3schools.com" );
      });
    </script>
  </head>
  <body>
    <div id="siteloader"></div>​        
  </body>
</html>
Jagadeesh
  • 121
  • 2
  • 7
  • Well, you are already using `.load()` for this. Just wrap this line with `$(document).ready(function() { your code });` – Regent Oct 10 '14 at 06:13
  • Even though its not working - Regent – Jagadeesh Oct 10 '14 at 06:15
  • I missed word **external**. Due to security reasons, you can't load pages from another domain. – Regent Oct 10 '14 at 06:23
  • 2
    IT is cross domain request . You need to enable CORS. – Pramod S. Nikam Oct 10 '14 at 06:26
  • Due to browser security restrictions, most "Ajax" requests are subject to the same origin policy; the request can not successfully retrieve data from a different domain, subdomain, port, or protocol. http://api.jquery.com/load/ – Fabio Oct 10 '14 at 06:52

2 Answers2

1

As proposed by @DefyGravity 's comment in this post about embedding pages, the site (in this case w3schools.com would need to allow your site to access the contents, for security purposes.

If you have access to the external site you'll access, it could be possible to send a Origin: http://requestSite.com header to http://w3schools.com, but w3schools.com would have to send back an Access-Control-Allow-Origin: http://requestSite.com header, but that's the only way I know it to be possible (and that's only if you have access to the server of the other site you want to load).

See the console output of this jsfiddle, which supports my theory above: http://jsfiddle.net/ctnopep3/

Community
  • 1
  • 1
ironicaldiction
  • 1,200
  • 4
  • 12
  • 27
  • Any other ways we can get the url and display the content without iframe or object. – Jagadeesh Oct 10 '14 at 07:14
  • 1
    Yep, that's what I'm pointing out to you @Jagadeesh . If you look at the console output (developer tools in your browser), you'll see that you get an XmlHttpRequest error, because no Access-Control-Allow-Origin header was sent. – ironicaldiction Oct 10 '14 at 07:14
  • None that are trivial...none others that I know of – ironicaldiction Oct 10 '14 at 07:15
-1

Maybe you would like to try CURL or Nokogiri

Yakob Ubaidi
  • 1,846
  • 2
  • 20
  • 23