Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to load url into div tag

Tags:

I have a <div id="content"> want to load url: http://vnexpress.net content into my code:

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

I don't want to use Iframe

like image 803
vinanghinguyen Avatar asked Dec 01 '11 00:12

vinanghinguyen


People also ask

Can we load a URL in div?

You can use jquery . load function to send the page to whatever html element you want to target, assuming your not getting this from another domain. iframes are old, another way we can add "src" into the html alone without any use for javascript.

How do I load a website into a div tag?

To load external HTML into a <div>, wrap your code inside the load() function. To load a page in div in jQuery, use the load() method.

How do you add another website to HTML?

Approach: To redirect from an HTML page to another page, you can use the <meta> tag by specifying the particular link in the URL attribute. It is the client-side redirection, the browsers request the server to provide another page.

Can div have SRC?

The HTML src attribute supports frame, iframe, img, input and script elements. It does not support the div element.


1 Answers

Try the load() function.

$('#content').load("http://vnexpress.net"); 

Please not that for this to work, the URL to be loaded must either be on the same domain as the page that's calling it, or enable cross-origin HTTP requests ("Cross-Origin Resource Sharing", short CORS) on the server. This involves sending an additional HTTP header, in its most basic form:

Access-Control-Allow-Origin:* 

to allow requests from everywhere.

like image 179
Carsten Avatar answered Oct 07 '22 16:10

Carsten