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
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.
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.
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.
The HTML src attribute supports frame, iframe, img, input and script elements. It does not support the div element.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With