Forum Moderators: open

Message Too Old, No Replies

Cross-window scripting and pre-existing window content

Any way to get most browsers to let you cross-script a non-empty window?

         

mincklerstraat

5:19 pm on Dec 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm writing a little app that opens a popup and writes info to it with document.writeln. The popup that's called just contains:

<BODY>
<SCRIPT LANGUAGE="JavaScript" type="text/javascript">
<!--
onLoad=opener.update();
//--></SCRIPT>
</BODY>

I am trying to add a whole slew of fancy HTML (and js for ie) - suckerfish dropdowns - for a bunch of toolbars. It'd be so, so nice to just have this HTML there in that popup already, with this bit of javascript at the bottom, so I don't have to encumber users' browsers with tens of lines of more document.writeln's - which I guess might get pretty heavy on lighter systems. Also, wouldn't it be pretty hairy doing the javascript output outputted itself in javascript? Just the light suckerfish ie javascript, but still - I can imagine this getting nasty.

The problem is that I have read that browsers will not allow for you to cross-window script in windows which already have HTML content. When I add my toolbar HTML to the popup, this is indeed true for Opera and Konqueror (KHTML, like Safari): they show the toolbars, but have none of the cross-window scripting output. Firefox, on the other hand, does show the cross-window output.

So my questions are:
1) Is it possible to somehow get the other important browsers - Opera, KHTML, and ie to do the cross-window scripting when other HTML content exists, or should I resign myself to having to have this HTML also output via cross-window scripting along with the rest?

2) Can I just use document.writeln to either link the javascript in a separate file, or else to write it out like normal cross-window scripting (properly escaped, of course), or will this fail to produce javascript that works?

rocknbil

6:47 pm on Dec 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not sure I understand the question but wanted to toss in -

...I have read that browsers will not allow for you to cross-window script in windows which already have HTML content

I'm pretty sure this only applies if the content does not originate on the same domain and is a security consideration. I just did this dance with a Real Estate customer who thought he was smart enough to outsmart his external MLS sites.

If it's on your domain you should be able to write to any windows you open if they are correctly referenced from any other window.

As for accessing the code from elsewhere, what you could do is put all your common code in an external .js and reference THAT from your pop-ups.

mincklerstraat

7:12 pm on Dec 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks for the answer, rocknbill. I guess I'm referencing the window correctly, since it does the output ok as is (the code posted above). The code from the parent window is like this:

var windowHandler = '';
var esite = '';
windowHandler = window.open('err.html','window_id_3866','toolbar=no,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=no,height=700,width=600');
if (!windowHandler.opener) windowHandler.opener = self;
function update() {
esite=windowHandler.document.open();
windowHandler.focus();
windowHandler.document.writeln('escaped HTML stuff');
esite=windowHandler.document.close();
}

When I add extra HTML to the <BODY> above the calling script inside the popup, Opera and Konqueror only show this HTML, and fail to show the stuff written by function update. I might just be doing this wrong, or maybe with this method there is some kind of cross-scripting with Opera and Konqueror?

Another thing I could do, I guess, is use an equivalent of PHP's readfile() if this exists in javascript, and just readfile() my toolbar HTML into the popup before the cross-site scripting content is written to it.

Any thoughts very much welcome; I'm quite the know-nothing when it comes to js.