473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to prevent JavaScript from executing in an iframe

Hi,

Is there some way from preventing the JavaScript code in a document
loaded into an iframe from executing? I don't have access to the pages
being loaded into the i-frame so I can't modify then. They are being
loaded from a server.

thanks again.

sean

Aug 31 '05 #1
4 5477
seans wrote:
Is there some way from preventing the JavaScript code
in a document loaded into an iframe from executing?
Disable javascript in your browser, or configure the browser to ask for
permission to execute each script, and deny it for the scripts in the
frames. If you mean that you want to prevent the execution of these
scripts on other user's browsers then you cannot, it is up to them to
make that decision.
I don't have access to the pages being loaded
into the i-frame so I can't modify then.
Does this mean they are someone else's pages?
They are being loaded from a server.


Now that is a novel idea :)

Richard.
Aug 31 '05 #2

Richard Cornford wrote:
seans wrote:
Is there some way from preventing the JavaScript code
in a document loaded into an iframe from executing?


Disable javascript in your browser, or configure the browser to ask for
permission to execute each script, and deny it for the scripts in the
frames. If you mean that you want to prevent the execution of these
scripts on other user's browsers then you cannot, it is up to them to
make that decision.
I don't have access to the pages being loaded
into the i-frame so I can't modify then.


Does this mean they are someone else's pages?
They are being loaded from a server.


Now that is a novel idea :)

Richard.


Hi Richard thanks for your reply. Yes they are somebody else's pages so
I can't make any changes to them.

thanks
sean

Aug 31 '05 #3
"seans" <se******@yahoo.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
Hi,

Is there some way from preventing the JavaScript code in a document
loaded into an iframe from executing? I don't have access to the pages
being loaded into the i-frame so I can't modify then. They are being
loaded from a server.


I may be misunderstanding your question but I'll give it a shot.

In general there's no simple way, but the matter rests on the source servers
for the material.

If the iFrame source is loaded from a server DIFFERENT from the one from
which the main page source was loaded then the browser security model will
prevent you from accessing the content of that page. There's no way around
this on the client-side (or, at the very least, any way around this is a
MAJOR security flaw).

In short: while you can load content from other servers into your frames and
iFrames you cannot actually "touch" that content at all. It's not yours -
hands off.

If the iFrame source is from the SAME server then you may be able to jury
rig something... but it will be a tenious solution at best. One obvious
option is to use XMLHttpRequest to fetch the source code meant for the
iFrame and maniplate it (strip out the script) before loading it into the
iFrame. This is riddled with problems however...

+) Any links or references in the iFrame will have to be examined: the
iFrame content's context will no longer be the same as if you allowed it to
be served normally. Relative links may (probably will) break. HREFs may
not (probably won't) function any longer.

+) As you've stated you have no control over the iFrame content, there's
nothing to stop it from changing and breaking your code (the likelyhood of
this happening in any so-called "screen scraping" operation is generally
assumed to be 1 in 1). If you're code to remove the offending script is too
specific it will probably break even sooner... if it's to general it will
probably break too much in the target page.

+) It also converts a simple task (changing the href of an iFrame) to a much
more complex one: this ain't never a good ideer.

All told it's really simplest to just consider it un-doable. ;^)

Jim Davis
Aug 31 '05 #4

Jim Davis wrote:
"seans" <se******@yahoo.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
Hi,

Is there some way from preventing the JavaScript code in a document
loaded into an iframe from executing? I don't have access to the pages
being loaded into the i-frame so I can't modify then. They are being
loaded from a server.


I may be misunderstanding your question but I'll give it a shot.

In general there's no simple way, but the matter rests on the source servers
for the material.

If the iFrame source is loaded from a server DIFFERENT from the one from
which the main page source was loaded then the browser security model will
prevent you from accessing the content of that page. There's no way around
this on the client-side (or, at the very least, any way around this is a
MAJOR security flaw).

In short: while you can load content from other servers into your frames and
iFrames you cannot actually "touch" that content at all. It's not yours -
hands off.

If the iFrame source is from the SAME server then you may be able to jury
rig something... but it will be a tenious solution at best. One obvious
option is to use XMLHttpRequest to fetch the source code meant for the
iFrame and maniplate it (strip out the script) before loading it into the
iFrame. This is riddled with problems however...

+) Any links or references in the iFrame will have to be examined: the
iFrame content's context will no longer be the same as if you allowed it to
be served normally. Relative links may (probably will) break. HREFs may
not (probably won't) function any longer.

+) As you've stated you have no control over the iFrame content, there's
nothing to stop it from changing and breaking your code (the likelyhood of
this happening in any so-called "screen scraping" operation is generally
assumed to be 1 in 1). If you're code to remove the offending script is too
specific it will probably break even sooner... if it's to general it will
probably break too much in the target page.

+) It also converts a simple task (changing the href of an iFrame) to a much
more complex one: this ain't never a good ideer.

All told it's really simplest to just consider it un-doable. ;^)

Jim Davis


Hi,

Sorry for the late reply. Thanks for all your responses.

sean

Sep 16 '05 #5

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

Similar topics

6
by: S'fly | last post by:
Hi, I'm struggling with the famous "gatekeeper" a little. Normally, it opens in a popup window, and from there it goes on. But I like this script to open in an iframe, and not in a popup. It...
3
by: Dany P. Wu | last post by:
Hi everyone, I am trying to create a site with pages containing iframes. This is the first time I've used inline frames and am still struggling with the concept. This site will have 10 pages...
3
by: Dave Anderson | last post by:
How can I make an onchange event update the src for an IFRAME? I would like to do it without reloading the page, is this possible? Dave
2
by: Robert Oschler | last post by:
I have an IFrame whose document is created completely by Javascript code at runtime. The document in the IFrame accesses Javascript functions in the top level document. This works fine most of...
3
by: cevatkerim | last post by:
Ok simple project! a login page with a hidden iframe when u click on submit after inserting your user and pass it pushes those values to iframe and asp query the db and returns a code if it is...
3
by: Ryu | last post by:
Hi, May I know how to prevent Javascript from being dlownloaded when the user saves at "View Source"? I have added "js" at IIS's application configuration's mapping and i have added the...
5
by: Lupus | last post by:
Hi everyone, I've got a problem with javascript. I have a webpage which contains some javascript functions and an iFrame which contains a second webpage: <html> <head> .... <script....>
9
by: gwong123 | last post by:
Hey, I need to convert this javascript code into iframe. The javascript goes into a server and brings out an ad banner. The X's is the server IP. <script language="javascript"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
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,...
0
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...
0
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,...
0
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...

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.