Andrew Scott wrote:[color=blue]
> Robby Bankston wrote:
>[color=green]
>> I'm working on some code and am running into brick walls. I'm trying
>> to write out Javascript with Javascript and I've read the clj Meta FAQ
>> and didn't see the answer, read many similar posts (with no luck
>> though), and searched through the IRT.ORG Faqs
>> (
www.irt.org/script/script.htm).
>>
>> The Javascript is designed to open an popup window and then inside that
>> window call another script which will resize that window. There may be
>> another way around this but the reason I tried this approach initially
>> was that I wanted to call the onload handler in the popup window to
>> resize the image only after the image had completely loaded. I've had
>> some code in the primary Javascript file (showimage.js) before that
>> works if the image has been cached but on the first load, it doesn't
>> resize properly which tells me it is probably because it is trying to
>> resize the window based on the image size but it isn't completely known
>> at that point. So I removed that code and tried placing the resizing
>> code in the second Javascript file (resizewindow.js). BTW I've tried
>> other code to open a popup image and automatically size it ie Q1443 at
>> irt.org but that doesn't do exactly what we need.
>>
>> Even if there is another way to do this with one file, I still want to
>> figure out why this isn't working in case I run into it in the future.
>>
>> I thought what I would need to do to use document.writeln to write
>> Javascript would be to escape any special characters and to break
>> apart the script tag ie
>>
>> document.writeln('<\/SCRIPT>');
>>
>> would become
>>
>> document.writeln('<\/SCR' + 'IPT>');
>>
>> I have a HTML page and 2 Javascript files. All files are in the same
>> directory and have permissions set correctly.
>>
>> Here are the 3 files (keep in mind wordwrap has jacked up the
>> formatting):
>>
>> index.html
>> ----------
>> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
>> <html>
>> <head>
>> <title>Test</title>
>> <SCRIPT type="text/javascript" LANGUAGE="JavaScript1.1"
>> SRC="showimage.js">
>> </SCRIPT>
>> </head>
>>
>> <body>
>> Click the house<BR>
>> <A ONCLICK="newWindow1('house1.jpg','Nice House')"><IMG
>> SRC="house1thumb.jpg"></A>
>> </body>
>> </html>
>>
>>
>> showimage.js
>> ------------
>> function newWindow1(pic,sitename)
>> {
>>
>> picWindow=window.open('','','width=25,height=25,sc rollbars=1,resizable=1');
>>
>> picWindow.document.writeln('<html> <head>');
>> picWindow.document.writeln('<SCR' + 'IPT type=\"text\/javascript\"
>> LANGUAGE=\"JavaScript1.1\" SRC=\"resizewindow.js\"><\/SCR' + 'IPT>');
>> picWindow.document.writeln('<\/head>');
>> picWindow.document.writeln('<body onload=\"resizewindow();\">');
>> picWindow.document.writeln('<img src=' + pic + '>');
>> picWindow.document.writeln('<\/body> <\/html>');
>> picWindow.document.close();
>> }
>>
>> resizewindow.js
>> ---------------
>> function resizewindow()
>> {
>> // Do resizing here.
>> // Right now this isn't being executed
>> alert("resizing window");
>> }
>>
>>
>> Can anyone provide some pointers as to why this javascript is failing?
>> I'm using IE6 on Win2k and when I click on the image to open the popup
>> window, it does open the window but it is white with no content and the
>> system immediately goes from about 4% CPU usage to 100% and
>> consistently stays there until I kill that window with the task
>> manager. I know I have something wrong in the code but I'm not sure
>> where. I appreciate any comments or tips. Thanks in advance.
>>
>> cheers
>> Rob
>>[/color]
>
>
> Hi Rob
>
> I think you should use propper DOM methods if you want to render another
> page. If you were to use propper DOM methods you won't have any issues
> adding scripts to your pages. To this date I have never seen a REAL need
> to use document.write("html"), except for maybe inline at render time,
> there are always other ways.
>
> And I don't understand why you are not loading a very simple html page
> and then inserting the img once the popup html has loaded.
>
> You might as well start with a blank canvas of html that you load in to
> the new window when it opens. And get that pages onload to call a
> funciton in the opener that loads the image and resizes the popup
>
> -------------------- HTML -----------------
> <html>
> <head></head>
> <body onload="opener.ChildLoaded(document)"></body>
> </html>
> -------------------------------------------
>
>
> ------------------ CODE -------------------
>
> var cPic = "";
> var picWindow = null;
> function newWindow1(pic,sitename)
> {
> cPic = pic;
> picWindow = window.open("URLtoSimpleHTML.url" ...... );
> }
>
> // this function will be called when it's loaded.
> function ChildLoaded(doc)
> {
> // using proper DOM methods to create Elemnts
> var eImg = doc.createElement("img");
> eImg.onload = funciton ()
> {
> alert( this.width + " :: " + this.height );
> // Do you resizing here on the global var
> // picWindow.
> }
> doc.body.appendChild( eImg );
> }
>
> -------------------------------------------
>
> HTH
>
> Andy
>
>
>
>
>
>[/color]
Opps, Missed a line of code out...
function ChildLoaded(doc)
{
// using proper DOM methods to create Elemnts
var eImg = doc.createElement("img");
eImg.onload = funciton ()
{
alert( this.width + " :: " + this.height );
// Do you resizing here on the global var
// picWindow.
}
*******************************
eImg.src = cPic;
*******************************
doc.body.appendChild( eImg );
}
Sorry about that....
Andy