Insert external page html into a page html
There are 2 solutions for this (2 that I know at least):
Iframe -> this one is not so recommended
Send an ajax request to the desired page.
Here is a small script:
<script type="text/javascript">
function createRequestObject() {
var obj;
var browser = navigator.appName;
if (browser == "Microsoft Internet Explorer") {
obj = new ActiveXObject("Microsoft.XMLHTTP");
} else {
obj = new XMLHttpRequest();
}
return obj;
}
function sendReq(req) {
var http = createRequestObject();
http.open('get', req);
http.onreadystatechange = handleResponse;
http.send(null);
}
function handleResponse() {
if (http.readyState == 4) {
var response = http.responseText;
document.getElementById('setADivWithAnIDWhereYouWantIt').innerHTML=response;
}
}
sendReq('yourpage');
//previously </script> was not visible
</script>
HTML - How to include external html page
You can use jquery to accomplish this task:
Just create a new file "modal.html" and write code for popup there.
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script>
$(function(){
$("#header").load("modal.html");
});
</script>
</head>
<body>
<div id="header"></div>
<!-- other code -->
</body>
Include another HTML file in a HTML file
In my opinion the best solution uses jQuery:
a.html
:
<html>
<head>
<script src="jquery.js"></script>
<script>
$(function(){
$("#includedContent").load("b.html");
});
</script>
</head>
<body>
<div id="includedContent"></div>
</body>
</html>
b.html
:
<p>This is my include file</p>
This method is a simple and clean solution to my problem.
The jQuery .load()
documentation is here.
How to include an HTML page into another HTML page without frame/iframe?
If you're just trying to stick in your own HTML from another file, and you consider a Server Side Include to be "pure HTML" (because it kind of looks like an HTML comment and isn't using something "dirty" like PHP):
<!--#include virtual="/footer.html" -->
Inserting html code from one page, into another html page
As per our chat:
https://chat.stackoverflow.com/rooms/131606/discussion-between-brandon-and-fred-ii
You need to run this as an admin, since this is a permissions issue under Windows 7.
Add an external HTML file into an existing HTML page
On WordPress you create a part template from your form e.g. form1.php in your theme folder. Then you can put this in your template with:
get_template_part( 'form1' );
On WordPress a good solution for forms is Contact Form 7 which will give you more flexibility with including the forms on your pages instead of fixing the form in the templates.
Load a HTML page within another HTML page
iframe
is the tag which you can use for call other html pages into your web page
<iframe
src="http://www.google.co.in"
name="targetframe"
allowTransparency="true"
scrolling="no"
frameborder="0"
>
</iframe>
Related Topics
Replace Multiple Whitespaces with Single Whitespace in JavaScript String
How to Extend a Class Without Having to Use Super in Es6
How to Delete Document from Firestore Using Where Clause
Angular2:Render a Component Without Its Wrapping Tag
How to Wait for a JavaScript Promise to Resolve Before Resuming Function
Check If Event Is Triggered by a Human
Ternary Operators in JavaScript Without an "Else"
How to Open a Url in a New Tab Using JavaScript or Jquery
Why Is It Object.Defineproperty() Rather Than This.Defineproperty() (For Objects)
What Does Three Dots Do in Reactjs
Angular2/Spring Boot Allow Cross Origin on Put
How to Get the Anchor from the Url Using Jquery
How to Find the Array Index with a Value
How to Conditionally Add Attributes to React Components
How to Get Last Characters of a String
Getelementsbyclassname() with Two Classes