[Javascript]Passive,Javascript-callable,in-line(PHP)codereferences wit

David Lovering dlovering at gazos.com
Wed Apr 9 13:53:13 CDT 2003


Having tried a number of various implementations suggested by different
people, I thought I'd report on the preliminary results:

  Andrew's Suggestion:

> <a href=javascript:parent.frames['hidden'].getData()><Get data from
server</a>
>
> and then in the hidden frame have the function populate a form and post
it.
> Then whenever data i get from the server, I write to a <div> or whatever
on
> the main page from the hidden frame.

Works great -- but only if the routine 'getData' is in fact JavaScript.
Doesn't work at all if the code is ASP, PHP, or
whatever server-side language is the lingo de jour.  Hardly seems worth it,
since I can "src" my JavaScript routines
directly into my header anyhow.

<span id='wrapper' style='display: none'><iframe id='myPHPcode'
src=''></iframe></span>

.... elsewhere ....

<input type='button' name='myButton' value='push me!'
onClick='myPHPcode.src="bogus.php"; wrapper.style.display="inline"'>

Doesn't work, but in a very strange way.  The .src redefinition works (as
can be seen by doing a post-mortem dump of the attributes), but the
wrapper.style.display change only shows an empty frame, and the embedded
code doesn't execute.  On the other hand, if one reduces the span definition
to

<span id='wrapper' style='display: none'><iframe id='myPHPcode'
src='bogus.php'></iframe></span>

and modifying the input 'onClick' handler to be merely

  onClick='wrapper.style.display="inline"'

then it displays as you'd expect, and the embedded PHP (or whatever) code
appears to have run once.

HOWEVER (!!!) the operable word here is 'once'.  The server-side code (true
of all the languages I tested) when embedded in a DIV or SPAN, FRAME or
IFRAME executes only upon load, and then never again.  Getting it to trigger
on another event (onMouseDown, for example) appears not to work.  Moreover,
when you try to roll the
display update directive and the src redirection together, it doesn't fly.
Maybe I'm dim, but it looks like something is missing...

The only way I've beaten this in the past is to foist the server code I
wanted to execute into a remote, and then backwards reference the output
back to the parent window.  UGLY!

Lest folks think I haven't cogitated about this, be it known that I even
tried to fake a load event by attaching a
fireEvent("onload") to the span and/or the iframe, and then kick it
subsequently.  No cigar.  Not only does it appear that this is not
syntactically correct, but even when the object constructors are jiggered to
force acceptance, it doesn't work.

Oh well, back to the drawing board...

-- Dave Lovering






More information about the Javascript mailing list