473,805 Members | 2,268 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

foist javascript upon another frame

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.htm l' >
</iframe>

That prototype.js gives us goodies like $(). And sample.html looks a little
bit like this:

<html><body bgcolor='silver '>
<span id='update_me'> yo</span>
</body></html>

Now I want to write a function that pushes some JavaScript into the iframe,
and evaluates it there. Should I use eval()? Is there some way to make
eval() execute in a frame's context?

Or should I foolishly write a function, in another js header, like this?

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

if (grinder)
{
var doc = grinder.content Document;
if (!doc) doc = grinder.documen t;
if (doc)
{
doc.body.innerH TML += '<script>' + nu_script + '</script>';
return;
}
}
document.write( " your browser lacks decent iframes");
}

And that doesn't work. The iframe appears to twitch (it will lose a
selection emphasis, for example), but it doesn't evaluate my script.

(For the script.aculo.us-enlightened, the script is just
Element.update( "update_me" , "here I B"), and it is correctly escaped and
transmitted. alert() statements can see it, just before the innerHTML+= line
where it does not work. Without the <scripttags, the new JS appears as
source, and with them it simply doesn't evaluate.

Can't I just say something obvious like doc.body.script = nu_script, or
less??

Please don't ask why I want to do this; I'm not attacking someone else's
page, or trying to write a public site using extra-fragile code. I just ...
need to do it!

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
Dec 16 '06
16 1848
Randy Webb whined:
>"I'm not ... trying to write a public site..."

<quote>
trying to write a public site using extra-fragile code.
</quote>
When a statement uses rhetorical ambiguity, rely on the first segment over
the second. I'm not trying to write a public site.
>Your sample page, while generally studious, does not actually do anything
to the target page at load time. All it does is load the JS and
demonstrate an 'alert()'. This does not prove the JS worked in the
context of the target browser.

It doesn't? The sample page (I assume you are actually referring to the
loadJSFile/ page) is a test page to see where different techniques work
(or fail) in different browsers. All of the results on that page are, to
the best of my knowledge, accurate. I did not do any of the Linux and Mac
testing so I depended on someone else for those results.
I need to inject JS across an iframe boundary. Your page is not about that.
I have lost count the number of times I clearly stated I am inserting from
one frame into another. Feel free to mis-quote again.
I assume you are referring to some HTML that looks something like this:

<span id="update_me"> some text or code<span id="update_me"> </span></span>
No. One span is in the hosting page and one is inside the iframe.
Where you have multiple instances of the ID nested within one another.
Why pretend you think anyone would do that? Except to allow you to continue
to drivel?

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
Dec 16 '06 #11
Phlip babbled the following on 12/16/2006 10:58 AM:
Randy Webb whined:
<snip>
>>Your sample page, while generally studious, does not actually do anything
to the target page at load time. All it does is load the JS and
demonstrate an 'alert()'. This does not prove the JS worked in the
context of the target browser.
It doesn't? The sample page (I assume you are actually referring to the
loadJSFile/ page) is a test page to see where different techniques work
(or fail) in different browsers. All of the results on that page are, to
the best of my knowledge, accurate. I did not do any of the Linux and Mac
testing so I depended on someone else for those results.

I need to inject JS across an iframe boundary.
Then you rewrite loadJSFile so that instead of appending to the current
document you append it to the IFrame's document.
Your page is not about that.
True. Well, not directly but it covers the basics. It only leaves you to
figure out how to do it across an IFrame is all.
I have lost count the number of times I clearly stated I am inserting from
one frame into another. Feel free to mis-quote again.
No need to quote, I told you how to document.write across frames, I
assumed you would be able to realize how to do a script injection across
frames. Do you know how to script at all??

Just for you though, and Today only, here is a function for you:

function insertScriptTex tAcrossFrames(f rameID,scriptSt ring){
frameRef = window.frames[frameID]
var newScript = frameRef.docume nt.createElemen t('script');
newScript.type = "text/javascript";
newScript.text = "alert('changeT ext worked')";
frameRef.docume nt.getElementsB yTagName('head' )[0].appendChild(ne wScript);
}

And then call it:

insertScriptTex tAcrossFrames(' myIFrame','eval ("Your mama")')
<snipped the whining babbling non-sense>

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 16 '06 #12
Phlip said the following on 12/16/2006 10:58 AM:
Randy Webb whined:
>>"I'm not ... trying to write a public site..."
<quote>
trying to write a public site using extra-fragile code.
</quote>

When a statement uses rhetorical ambiguity, rely on the first segment over
the second. I'm not trying to write a public site.
That is not what you said, please make sure you write what you mean. It
will save you a lot of trouble.

Is your real name Thomas Lahn?

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 16 '06 #13
Randy Webb wrote:
newScript.text = "alert('changeT ext worked')";
Alert doesn't use the context of the target object, like I already said. Try
updating a div in the target.

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
Dec 16 '06 #14
In article <GI************ **@newssvr19.ne ws.prodigy.com> , Phlip
<ph******@yahoo .comwrites

<snip>
><span id="update_me"> some text or code<span id="update_me"> </span></span>

No. One span is in the hosting page and one is inside the iframe.
>Where you have multiple instances of the ID nested within one another.

Why pretend you think anyone would do that? Except to allow you to continue
to drivel?
The HTML 4 standard doesn't guarantee that you're allowed the same ID in
the two parts.

John
--
John Harris
Dec 16 '06 #15
John G Harris wrote:
The HTML 4 standard doesn't guarantee that you're allowed the same ID in
the two parts.
I don't want to. The two IDs were to illustrate the bug. Without the second
SPAN with the same ID, I

The point, like I hinted in the subject line, was evaluating JS across a
frame boundary. So does HTML 4 say frames may happen to share the same IDs?
(I will make sure they don't anyway...)

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
Dec 17 '06 #16
>The HTML 4 standard doesn't guarantee that you're allowed the same ID in
>the two parts.

I don't want to. The two IDs were to illustrate the bug. Without the
second SPAN with the same ID, I
....get the same bug, with a different symptom; IE's JS throws an error
because it can't find the correct ID, which is right there...
The point, like I hinted in the subject line, was evaluating JS across a
frame boundary. So does HTML 4 say frames may happen to share the same
IDs? (I will make sure they don't anyway...)

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!


Dec 17 '06 #17

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

Similar topics

15
2279
by: Phlip | last post by:
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:
0
9718
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
9596
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
10614
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...
1
7649
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5544
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4327
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
3847
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.