Phlip wrote:
Rails Spinoffers:
Steps to reproduce the bug:
This does not show a bug. It shows that if you call a function that is
out of scope, you'll get an error.
Save this in "outer.html":
<div id='updateMe'></div>
<iframe src='inner.html'/>
Now save this into "inner.html":
<input type='button' value='control'
onclick="window.parent.location.href =
"javascript:void(document.getElementById('updateMe').innerHTML
= 'control')""/>
Why you are using the javascript pseudo-protocol to execute script
commands plumb evades me. Why not:
onclick =
"window.parent.document.getElementById('updateMe').innerHTML =
'control';">
<script src="/javascripts/prototype.js?1168956448"
type="text/javascript"></script>
If you are going to call Prototype.js functions in the *parent* window,
then you'd better make them available in the parent window, not in the
iFrame window. Each has a separate global object and scope.
Incidentally, $() is not a replacement for document.getElementById. It
is a way of ensuring that the object used is a Prototype DOM object,
not a plain DOM object.
[...]
Observed behaviour:
Click 'experiment', and observe a null-object crash. $() could not
find the same value as getElementById().
The error is because $ is not defined - Firefox reports "$ is not
defined", IE shows "object expected" coming from outer.html.
Expected behavior:
Because the javascript:void trick evaluates in the context of the
target frame (not the source frame), the behaviors of $() and
getElementById() should be exactly the same inside the
javascript:void() line as inside the target frame, right?
No. You call:
parent.window.location.href = "javascript:<script commands>";
Therefore the value of the parent window's location.href property is
set to the *string* value assigned. The javascript pseudo-protocol
causes the *string* to be executed in the context of that window.
QED.
Move (or copy) the script element that loads the Prototype.js file into
the parent window and the mystery is solved.
--
Rob
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on
Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---