Is there a way with jQuery to load Html contents from a url?
For example:
<div class="MyContent">
<html>
<head>
<title>Hello World Page</title>
</head>
<body>
Hello World
</body>
</html>
</div>
Can I replace all of the HTML above in the div with the content from a URL?
You're looking for .load()
Load data from the server and place the returned HTML into the matched element.
Firstly, create an HTML page with this code
<html>
<head>
<title>Hello World Page</title>
</head>
<body>
Hello World
</body>
</html>
Have an iFrame inside a DIV (optional) and change the source of the iFrame to URL using jQuery. The url should point to the page you create above.
function loadIframe(iframeName, url) {
var $iframe = $('#' + iframeName);
if ( $iframe.length ) {
$iframe.attr('src',url);
return false;
}
return true;
}
using .get()
and .html()
in jQuery. ex,
$.get(url, function (data) {
$('.MyContent').html(data);
});