Click to See Complete Forum and Search --> : How to grab the HTML code from another HTML file - HELP :(


kkleong
04-17-2003, 10:36 PM
:confused: Hi there all the JavaScript Pro, I need help as I am in the middle of doing a simple web builder project. The web builder should be able to call out different templates and display on the WYSIWIG editor for user to build their web page...But I am having some problems as I tried to call out the web template files into my WYSIWIG editor, the template has beeing called out in a Browse View and not in Edit Mode... which means the user can see the template in the editor but not able to edit the page at all...

Therefore I would need to call out the HTML coding from the template and dump it into my editor file in order to have an active editing mode..... but somehow i am not sure is there any script that can do the job??

I just need a script or alternative ways in grabbing the template coding and insert it into another file... any ideas??

Thanks for the help in advance....

DrDaMour
04-17-2003, 10:43 PM
if that other html file has <div id=""> type nature you can use the id.innerHTML object to grab it, but even still this is a hard thing to do with javascript. What you prepose is not the simplest thing to implement by any means

khalidali63
04-17-2003, 10:52 PM
The best way to do something like this would be use of a core programming lang that can read a file from disk,However,you can use the following hack to get the html code of a document provided that the document is a child window created from the parent window.

is a frame in the frameset
or as mentioned in the above post an element in the current page.

here is an example of getting the html code from a frame
var html =parent.frameName.document.getElementsByTagName("html"[0].innerHTML;
alert(html)
this will give you all the code in a page excluding <html> tags.Ofcourse there could be a debate that is it the most appropriate way????/

viravan
04-17-2003, 11:22 PM
Originally posted by kkleong
I just need a script or alternative ways in grabbing the template coding and insert it into another file... any ideas??


The following is a script that I worked on a few years back...it may still work, so why don't you check it out:


<HTML xmlns:msie>
<msie:download id="downloader" style="behavior:url(#default#download)" />
<HEAD>
<SCRIPT>
(document.all) ? NS=false : NS=true;
if (NS) {document.captureEvents(Event.KEYPRESS);}
document.onkeypress=keyCheck;
function keyCheck(e)
{
(NS) ? kCode=e.which : kCode=event.keyCode;
if (kCode==13) {loadFile();return false;}
return true;
}
function fetchURL(url)
{
if ((location.host == '' && url.indexOf(location.protocol)==-1) || url.indexOf(location.host)==-1)
{netscape.security.PrivilegeManager.enablePrivilege("UniversalConnect");}
var dest=new java.net.URL(url);
var dis=new java.io.DataInputStream(dest.openStream());
var res=new Array();
var i=0;
while ((line=dis.readLine())!=null) {
res[i]=String(line);
i++;
}
dis.close();
(res.length==0) ? alert(file+" is mpty or non-existent!") : alert(res);
}
function loadFile()
{
(NS) ? fileName=document.xxx.filnam.value : fileName=document.getElementById("xxx").filnam.value;
if (fileName=="") {alert("File name not specified!");return;}
if (document.all && document.getElementById) {
downloader.startDownload(fileName,displayFile);
} else {
var i=new Image();
i.src=fileName;
var fileURL=i.src;
fetchURL(fileURL);
}
}
function displayFile (text) {
(text.length==0) ? alert(file+" is empty or non-existent!") : alert(text);
}
</SCRIPT>
</HEAD>
<BODY>
Enter name of text file to list (e.g., nocache.txt)
<form name="xxx"><input type="text" name="filnam" value="nocache.txt" size=50>
</form>
<script>
(NS) ? document.xxx.filnam.focus() : document.getElementById("xxx").filnam.focus();
</script>
</BODY>
</HTML>



:)

V.V.

khalidali63
04-17-2003, 11:43 PM
Nice piece a code V.V.
Though I see it seems like it will only work in NS browsers because of all the java code in it.

Khalid

viravan
04-18-2003, 07:52 AM
Originally posted by khalidali63
Nice piece a code V.V.
Though I see it seems like it will only work in NS browsers because of all the java code in it.

Khalid

Thanks.....

As I said before, I haven't done any scripting in the past few years but you should check it out, it used to work on IE5.5 and NN4.79 (didn't test on NN6 which was very buggy back then).... note this very first line of code:


<HTML xmlns:msie>



:)

V.V.