Reprocess page after document.write

P

Paul Thompson

I am working with a special tool which pre-processes the page. Using
document.write, I am composing the page while it is loading, so I need
to force a reprocess of the page AFTER the page loads.

Is there some way to do that? That is, I want the browser to
essentially act as if the composed page was the original page.


Here is a brief version of the page construction technique:

<!DOCTYPE HTML SYSTEM "-//W3C//DTD XHTML 1.0 Strict//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript"><SCRIPT
LANGUAGE="JavaScript" TYPE="text/javascript">
nxitm=" ";iam=" ";setstart=1;comx=0;holdshf=false;zmaxv=0;
function oneitem(curp,chkVls,chkNms) {
alert('curp:'+curp+',name:'+chkNms[curp+11]+",val:"+chkVls[curp+11]);
var cma=0;var cmb=0;var retstr=' ';
if (chkVls[curp+11] == 1) {
if (chkVls[curp] == 1) {cma=1;}
if (chkVls[curp+5] == 1) {cmb=1;}
retstr='{sq'+'l} INSERT into shal';
retstr=retstr='tpkd.cmfform(pw=haltpwd) {\s'+'ql}';
}
return (retstr);
}
// get document.location, decode, assign
var chkStr = document.location.href.split('?')[1].split('&');
var chkNms = document.location.href.split('?')[1].split('&');
var chkVls = document.location.href.split('?')[1].split('&');
for(var x=0; x<chkStr.length; x++)
{
var tmp = chkStr[x].split('=');
chkNms[x]=unescape(tmp[0]);
chkVls[x]=unescape(tmp[1]);
eval(unescape(tmp[0]) + '="' + unescape(tmp[1]) + '"');
}
var restpage='<!DOCTYPE HTML SYSTEM "-//W3C//DTD XHTML 1.0 ';
restpage=restpage+'Strict//EN">';
restpage=restpage+'<HTML><HEAD><TITLE>Concomitant ';
restpage=restpage+'Medications Form</TITLE>';
restpage=restpage+'<SCRIPT LANGUAGE="JavaScript"';
restpage=restpage+' TYPE="text/javascript"';
restpage=restpage+' SRC="http://localhost/haltpkd/java/mainjava.js">';
restpage=restpage+'</SC'+'RIPT>';
restpage=restpage+'<L'+'INK REL=STYLESHEET type="text/css"';
restpage=restpage+' HREF="http://localhost/haltpkd/css/maincss.css">';
restpage=restpage+'</L'+'INK>';
restpage=restpage+'</H'+'EAD>';
restpage=restpage+'<BO'+'DY>';
restpage=restpage+'<FO'+'RM NAME="cmfform" METHOD="POST">';
restpage=restpage+'{up'+'date server="rook:haltpkd" sapw="milo99ha"}';
restpage=restpage+'{lib'+'rary sqlname="shaltpkd"';
restpage=restpage+'path="/data/pkdtn/linux"}';
restpage=restpage+'<INPUT TYPE="HIDDEN" NAME="_haltid"';
restpage=restpage+' VALUE="'+chkVls[0]+'">';
for (curp=13;curp<chkVls.length-12;curp=curp+14) {
restpage=restpage+oneitem(curp,chkVls,chkNms);
}
restpage=restpage+'{/upd'+'ate}';
restpage=restpage+'<SCRIPT LANGUAGE="JavaScript"';
restpage=restpage+' TYPE="text/javascript">';
restpage=restpage+'document.cmfform.action=actstr+"getv.hsql";';
restpage=restpage+'document.cmfform.submit();';
restpage=restpage+'</SC'+'RIPT> </F'+'ORM> </B'+'ODY> </H'+'TML>';
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="cmfform" METHOD="POST">
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
document.write(restpage);
</SCRIPT>
</BODY> </HTML>
 
E

Erwin Moller

Paul Thompson wrote:

I am working with a special tool which pre-processes the page. Using
document.write, I am composing the page while it is loading, so I need
to force a reprocess of the page AFTER the page loads.

Is there some way to do that? That is, I want the browser to
essentially act as if the composed page was the original page.

Hi Paul,

A suggestions that comes into mind (without any knowledge of all the
difficulties your are in):
Why not buffer the complete output in a var, and when done, write that?

Regards,
Erwin Moller
 
R

Robert

Paul Thompson said:
I am working with a special tool which pre-processes the page. Using
document.write, I am composing the page while it is loading, so I need
to force a reprocess of the page AFTER the page loads.

Is there some way to do that? That is, I want the browser to
essentially act as if the composed page was the original page.

What is failing?

You only need to escape the </script> tag. An easier way to do this is:
<\/script>. When a browser sees, <script> it scans for the </script>
tags. Some browser ignore things in quotes in when doing this scan.
Hence the need for escaping.


See RobG's explains how to construct a string containing html. Grooge
won't let me point to one post but only a thred. Here is the thread:

http://groups-beta.google.com/group/comp.lang.javascript/browse_thread/th
read/f8d72fff92b97c76/ddd4888398a775c1?q=robg+Cant+correctly+load+.js&_do
ne=%2Fgroup%2Fcomp.lang.javascript%2Fsearch%3Fgroup%3Dcomp.lang.javascrip
t%26q%3Drobg+Cant+correctly+load+.js%26qt_g%3D1%26searchnow%3DSearch+this
+group%26&_doneTitle=Back+to+Search&&d#ddd4888398a775c1

RobG Oct 14 2004, 8:17 pm
Subject: Re: Cant correctly load .js files when creating page
dynamically in IE

Here is RobG's code. Hope he doesn't mind.

<html>
<head>
<title>New Page</title>
<script type="text/javascript">
function loadWindow() {
var VE3DWindow = window.open('',
'VE3DWin','resizable=1,width=400,height=400')
var a = [
'<!DOCTYPE HTML PUBLIC ',
'"-//W3C//DTD HTML 4.01 Transitional//EN"',
'"http://www.w3.org/TR/html4/loose.dtd">',
'<html>',
'<head>',
'<meta http-equiv="Content-Type" ',
'content="text/html; charset=iso-8859-1">',
'<title>Untitled Document</title>',
'<script type="text/JavaScript" src="xx.js"></scr',
'ipt>',
'<script type="text/JavaScript">alert(location);</scr',
'ipt>',
'</head>',
'<body>',
'<p>Here is a page</p><p>here is some text</p>',
'<p>and some more text</p>',
'<form action=""><input type="button" ',
'value="Open Window"',
'onclick="xx();"></form>',
'</body>',
'</html>',
];
VE3DWindow.document.write(a.join(""))
VE3DWindow.document.close()
}

</script>
</head>
<body>
<form action="">
<input type="button" value="Open Window"
onclick="loadWindow();">
</form>
</body>
</html>

file xx.js:

function xx() {
alert('hi');
}


Robert
 
R

Robert

Paul Thompson said:
I am working with a special tool which pre-processes the page. Using
document.write, I am composing the page while it is loading, so I need
to force a reprocess of the page AFTER the page loads.

There are a lot of bugs in the posted code. Try running the code in
Firefox and look at the javascript console. I made some changes but
after the first 7 errors I have stopped. The first error was a missing
</script> tag on the first script line.

the line:
restpage=restpage+'Strict//EN">';
can be written as:
restpage += 'Strict//EN">';

<!DOCTYPE HTML SYSTEM "-//W3C//DTD XHTML 1.0 Strict//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript"></SCRIPT>
<script LANGUAGE="JavaScript" TYPE="text/javascript">
nxitm=" ";iam=" ";setstart=1;comx=0;holdshf=false;zmaxv=0;
function oneitem(curp,chkVls,chkNms) {
alert('curp:'+curp+',name:'+chkNms[curp+11]+",val:"+chkVls[curp+11]);
var cma=0;var cmb=0;var retstr=' ';
if (chkVls[curp+11] == 1) {
if (chkVls[curp] == 1) {cma=1;}
if (chkVls[curp+5] == 1) {cmb=1;}
retstr='{sq'+'l} INSERT into shal';
retstr=retstr='tpkd.cmfform(pw=haltpwd) {\s'+'ql}';
}
return (retstr);
}
// get document.location, decode, assign
/*
var chkStr = document.location.href.split('?')[1].split('&');
var chkNms = document.location.href.split('?')[1].split('&');
var chkVls = document.location.href.split('?')[1].split('&');
for(var x=0; x<chkStr.length; x++)
{
var tmp = chkStr[x].split('=');
chkNms[x]=unescape(tmp[0]);
chkVls[x]=unescape(tmp[1]);
eval(unescape(tmp[0]) + '="' + unescape(tmp[1]) + '"');
}
actstr = " ";
var restpage='<!DOCTYPE HTML SYSTEM "-//W3C//DTD XHTML 1.0 ';
restpage=restpage+'Strict//EN">';
restpage=restpage+'<HTML><HEAD><TITLE>Concomitant ';
restpage=restpage+'Medications Form</TITLE>';
restpage=restpage+'<SCRIPT LANGUAGE="JavaScript"';
restpage=restpage+' TYPE="text/javascript"';
restpage=restpage+' SRC="http://localhost/haltpkd/java/mainjava.js">';
restpage=restpage+'</SC'+'RIPT>';
restpage=restpage+'<L'+'INK REL=STYLESHEET type="text/css"';
restpage=restpage+' HREF="http://localhost/haltpkd/css/maincss.css">';
restpage=restpage+'</L'+'INK>';
restpage=restpage+'</H'+'EAD>';
restpage=restpage+'<BO'+'DY>';
restpage=restpage+'<FO'+'RM NAME="cmfform" METHOD="POST">';
restpage=restpage+'{up'+'date server="rook:haltpkd" sapw="milo99ha"}';
restpage=restpage+'{lib'+'rary sqlname="shaltpkd"';
restpage=restpage+'path="/data/pkdtn/linux"}';
restpage=restpage+'<INPUT TYPE="HIDDEN" NAME="_haltid"';
restpage=restpage+' VALUE="'+chkVls[0]+'">';
for (curp=13;curp<chkVls.length-12;curp=curp+14) {
restpage=restpage+oneitem(curp,chkVls,chkNms);
}
restpage=restpage+'{/upd'+'ate}';
restpage=restpage+'<SCRIPT LANGUAGE="JavaScript"';
restpage=restpage+' TYPE="text/javascript">';
restpage=restpage+'document.cmfform.action=actstr+"getv.hsql";';
restpage=restpage+'document.cmfform.submit();';
restpage=restpage+'</SC'+'RIPT> </F'+'ORM> </B'+'ODY> </H'+'TML>';
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="cmfform" METHOD="POST">
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
document.write(restpage);
</SCRIPT>
</BODY> </HTML>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top