sairfan1 Posted March 2, 2010 Share Posted March 2, 2010 Hii want to include a html file from out side for example//main.html<html><body> <div> .. include footer.htm </div></body></html>Please advise how to add Link to comment Share on other sites More sharing options...
real_illusions Posted March 2, 2010 Share Posted March 2, 2010 You need to look into Server Side Includes (SSI) - http://www.w3schools.com/php/php_includes.aspNote - the page using the PHP include page needs to be .php (or set up to parse php) and needs to be run on a server running PHP. Link to comment Share on other sites More sharing options...
sairfan1 Posted March 4, 2010 Author Share Posted March 4, 2010 im using static .htm pages, is there some other way??or how can i do it through javascript??thanks You need to look into Server Side Includes (SSI) - http://www.w3schools.com/php/php_includes.aspNote - the page using the PHP include page needs to be .php (or set up to parse php) and needs to be run on a server running PHP. Link to comment Share on other sites More sharing options...
Synook Posted March 4, 2010 Share Posted March 4, 2010 You can use AJAX. Link to comment Share on other sites More sharing options...
student101 Posted March 4, 2010 Share Posted March 4, 2010 You can use AJAX.How? Link to comment Share on other sites More sharing options...
Synook Posted March 4, 2010 Share Posted March 4, 2010 Well, depends how you define "outside", I suppose. If the page to be included is from the same domain, just using the XMLHttpRequest object would suffice, however if he means from another domain, then yes, you can't do it with just JavaScript but need some form of proxy on your host to fetch the page for you.http://www.w3schools.com/ajax/ Link to comment Share on other sites More sharing options...
student101 Posted March 4, 2010 Share Posted March 4, 2010 Well, depends how you define "outside", I suppose. If the page to be included is from the same domain, just using the XMLHttpRequest object would suffice, however if he means from another domain, then yes, you can't do it with just JavaScript but need some form of proxy on your host to fetch the page for you.I think that most of the time it would be same domain/site, guess I would need to find an example of this XMLHttpRequest object for including files like iframes. Link to comment Share on other sites More sharing options...
thescientist Posted March 4, 2010 Share Posted March 4, 2010 guess I would need to find an example of this XMLHttpRequest object for including files like iframes.did you check the link he posted? Link to comment Share on other sites More sharing options...
student101 Posted March 4, 2010 Share Posted March 4, 2010 did you check the link he posted?Yes, you talking about this example?<html><head><script type="text/javascript">function loadXMLDoc(url){if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); }else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }xmlhttp.open("GET",url,false);xmlhttp.send(null);document.getElementById('test').innerHTML=xmlhttp.responseText;}</script></head><body><div id="test"><h2>Click to let AJAX change this text</h2></div><button type="button" onclick="loadXMLDoc('test1.txt')">Click Me</button><button type="button" onclick="loadXMLDoc('test2.txt')">Click Me</button></body></html> I feel i've changed the topic posted from irfan ullahHe's example would be something like this; <!--#include virtual="somefile.inc"--><!--#include file ="somefile.inc"--><?php require("file_to_include.php"); ?><script type="text/javascript" src="path to file/include-file.js"></script>SSI (server side includes)<!--#include virtual="path to file/include-file.html" --> Link to comment Share on other sites More sharing options...
Synook Posted March 5, 2010 Share Posted March 5, 2010 I don't understand what you are trying to say. JavaScript's XMLHttpRequest object allows you to make asynchronous HTTP requests to the current domain and manipulate the results, for example by inserting the response text into an existing part in the page, like a server-side include would. I don't see how iframes come into it. You don't need to use any form of server-side language with AJAX, either, as your example seems to imply.http://www.google.com.au/search?q=include+page+ajax Link to comment Share on other sites More sharing options...
student101 Posted March 5, 2010 Share Posted March 5, 2010 I don't understand what you are trying to say. JavaScript's XMLHttpRequest object allows you to make asynchronous HTTP requests to the current domain and manipulate the results, for example by inserting the response text into an existing part in the page, like a server-side include would. I don't see how iframes come into it. You don't need to use any form of server-side language with AJAX, either, as your example seems to imply.My question was answered looking at the ajax url posted by you; (posted the code, to make it clearer for me), same as including files like iframes except more code and better, If iframes are fround upon why do CMS's like FCKeditor still use them?Edit;I am a serious FCKeditor fan! Link to comment Share on other sites More sharing options...
Synook Posted March 5, 2010 Share Posted March 5, 2010 WYSIWYG editors such as FCKeditor work by using iframes to display the generated HTML code. While you maybe could (somehow) use AJAX for this*, you will then run into problems with conflicting CSS styles, superfluous tags, etc.* there is actually a specific part of JavaScript for making WYSIWYG editors with, which includes commands like execCommand() and properties like contentEditable, but they are not perfectly supported yet. So until then, iframes it is. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.