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

Peter-Paul Koch gassinaumasis at hotmail.com
Wed Apr 9 14:55:18 CDT 2003



> > <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

I *think* that's because the browser encounters an error when it tries to 
execute the myPHPcode.src . .src is generally not a reliable way to refresh 
an iframe. See http://www.xs4all.nl/~ppk/js/index.html?iframe.html for the 
gory details. Conclusion: use

frames['myPHPcode'].location.href = 'bogus.php';

><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.

You directly assign a src to the iframe, which *is* allowed.

>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...

See above.

>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.

fireEvent is IE5.5+ Windows only. Moreover, assigning event handlers to 
documents inside iframes is unexplored territory. I've heard reports that 
it's not really possible, but haven't tested it myself yet.

--------------------------------------------------
ppk, freelance web developer
Interaction, copywriting, JavaScript, integration
http://www.xs4all.nl/~ppk/
Column "Keep it Simple": http://www.digital-web.com/columns/keepitsimple/
--------------------------------------------------


_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 2 months FREE*. 
http://join.msn.com/?page=features/featuredemail



More information about the Javascript mailing list