473,802 Members | 2,172 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

foist javascript into another frame, and evaluate it in the target context

Javascripters:

I have an outer page and an inner iframe. The outer page calculates some
javascript, and wants the inner frame to run it. The inner frame should hit
a page on the same (private) web server, so this is not a cross-site
scripting attack. But I would prefer not to taint the target page with any
extra logic to do this. (I will if I must.)

The calling page has these elements:

<script src="/javascripts/prototype.js" type="text/javascript" />...
<span id='update_me'> yo2</span>
<iframe id='grinder' src='sample.htm l' >
</iframe>

So here's most of the page which the iframe hits:

<script src="/javascripts/prototype.js" type="text/javascript" />...
<body bgcolor='silver '>
<span id='update_me'> yo</span>
</body></html>

Note that both the outer and inner page have a span with the same ID.

This question will resemble a JavaScript FAQ - how to evaluate Javascript on
the fly, or how to reload a JS file. The answers on the web generally do not
transport the JS across a frame boundary, so they don't address the bug I
encountered, and I can't tell if prototype.js or IE is at fault.

The outer page calls Ajax goodies that generate some JS looking like this:

Element.update( "update_me" , "here I B");

The page sends that, as a string, into this JS (in application.js) :

function update_grinder( sauce)
{
var grinder = $('grinder');

if (grinder)
{
var doc = grinder.content Document;
if (!doc) doc = grinder.documen t;
if (doc)
{
evaluate(doc, sauce);
return;
}
}
document.write( "your browser sucks");
}

So that contains enough logic to find the iframe's document, and it works
for Firefox, IE, Konqueror, and Opera. The code calls evaluate() with the
document where we need the evaluation context, and the string with our
source.

Here's evaluate():

function evaluate(doc, sauce)
{
var s = doc.createEleme nt('script');
//s.defer = true; // <-- no effect
s.text = sauce;
var body = doc.getElements ByTagName('body ').item(0);

if (body)
{
body.appendChil d(s);
return;
}
body = doc.body;
if (body)
{
body.appendChil d(s);
return;
}
}

That creates a <scriptblock, sticks our string in as its contents, and
pushes the block to the end of our <bodytag. Now here's the bug:

Firefox updates the inner <span id='update_me'> , and IE updates the outer
one.

If I remove the outer <span id='update_me'> , then IE simply can't find it
and throws an error. Even though it evaluates a script block clearly in the
context of the inner iframe.

I have tried calling the script from setTimeout, and from a button's onclick
handler.

Is there some script.aculo.us way to fix (yet another) bug in IE? Or is this
a bug in prototype.js?

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
Dec 16 '06
15 2277
Phlip said the following on 12/17/2006 12:59 AM:
Randy Webb wrote:
>And I posted code that does what you want it to do but it works,
flawlessly, in IE, so, where is the "bug"?

Forget the duplicate ID. FireFox updated the SPAN that Element.Update
targetted. IE threw an exception in the same situation. So there's a bug in
IE or prototype.js.
If hard coding it doesn't produce an exception but using Element.Update
produces that exception, then it points to the flaw being in
Element.Update, don't you think?

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 17 '06 #11
Randy Webb wrote:
If hard coding it doesn't produce an exception but using Element.Update
produces that exception, then it points to the flaw being in
Element.Update, don't you think?
Hard coding what??

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
Dec 17 '06 #12
Phlip said the following on 12/17/2006 2:30 AM:
Randy Webb wrote:
>If hard coding it doesn't produce an exception but using Element.Update
produces that exception, then it points to the flaw being in
Element.Update , don't you think?

Hard coding what??
<eyerollIf writing code to update an Element doesn't produce an
exception, yet trying to use Element.Update to update an Element
produces an exception, then the flaw is in Element.Update

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 17 '06 #13
Phlip wrote:
Randy Webb wrote:
>>>My "phobia of prototype.js"? That is, indeed, a powerful
assumption on your part. I have not expressed a phobia of
prototype

Besides calling it, what, "protocrap" ? Was that just the
exception?

Yep, that is what I called it. But I have no phobia of it,
its crap. If people want to use it, then let them.

"Phobia" means "hatred". Its popular usage is "unreasonin g
fear". Same difference.
<snip>

The deprecation of Prototype.js is not unreasoning. The library started
off being needlessly non-cross browser (failing on IE versions 5-5.5 for
no good reason and inconstant in its behaviour on Opera browsers), was
written in breach of the only naming convention stated in the language
specification, and recent modifications have rendered the library not
even ECMAScript compliant (so there should be no expectation of its ever
working outside of a known and limited set of nameable environments
(which defeats the whole drive towards standardisation in web
technologies)). It is also crazily convoluted in design and completely
interdependent, to the point that no novice stands a chance of
understanding how it works internally (partly as a result of having to
understand everything before they can understand anything), massively
inefficient and very much working against the strengths of javascript.
It worked in Firefox. In IE, the update went to the SPAN in
the outer frame. Bug. The possibility of invalid HTML
encodings doesn't excuse the bug.
Its behaviour in IE was accounted for entirely by your assumption that
the - document - property of an IFRAME element would refer to the
document contained in the IFRAME instead of the document containing the
IFRAME. That assumption was false and the consequences of your making
false assumptions cannot be attributed to bugs in IE.
function update_grinder( sauce)
{
var grinder = $('grinder');
grinder.src='ja vascript:void(f unction(){'+sau ce+'}())';
Be aware that executing a javascript pseudo-protocol URL on IEs 4-6
changes the state of the browser's execution environment in many ways
and much of what was reliable before doing so will not be reliable
afterwards. (This issue may have been removed from IE 7 as the most
visible symptoms of the state change are no longer observed there).

That means that if you do this in IE 6 all bets are off as to what you
may be able to do afterwards.

Also, there is no public specification that states that assigning to
the - src - attribute of an IFRAME will result in changes to the
contained document (and the implication of what the HTML DOM
specification actually does say is that it will not). Generally, if you
wanted to navigate (which is what this is attempting, in a not actually
navigating way) then you would assign the URL to the location object of
the frame/window/global object of the contained frame.

Richard.
Dec 17 '06 #14
Richard Cornford wrote:
The deprecation of Prototype.js is not unreasoning.
Yet its Phobia (true meaning, not popular usage) caused friction in this
benighted thread. At no time did I defend it, yet was repeatedly and
mindlessly attacked for suggesting it was an external constraint to my
quest.

And look! we found a bug in it! I only had to withstand getting flamed
numerous times to force that acknowledgement .

While you are such a font of knowledge, any idea why Konqueror doesn't work
there?

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
Dec 17 '06 #15
Phlip said the following on 12/17/2006 11:18 AM:
Richard Cornford wrote:
>The deprecation of Prototype.js is not unreasoning.

Yet its Phobia (true meaning, not popular usage) caused friction in this
benighted thread.
Only in your mind.
At no time did I defend it, yet was repeatedly and mindlessly attacked
for suggesting it was an external constraint to my quest.

"repeadtedl y and mindlessly"? You call one instance of me calling it
protocrap as repeatedly and mindlessly? You are the one that wouldn't
let it go. And then you went on to tell me I had no clue what you were
talking about - even after I proved you utterly wrong.
And look! we found a bug in it! I only had to withstand getting flamed
numerous times to force that acknowledgement .
I never said there wasn't a bug in prototype, I said it was possible and
that it was *not* a bug in IE and it's not.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 18 '06 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
1846
by: Phlip | last post by:
Javascripters: I have a page with an iframe inside. Let's say the iframe looks like this: <script src="/javascripts/prototype.js" type="text/javascript" /> .... <iframe id='grinder' src='sample.html' > </iframe> That prototype.js gives us goodies like $(). And sample.html looks a little
0
9699
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9562
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10536
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10304
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10285
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10063
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9114
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
4270
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3792
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.