473,796 Members | 2,916 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

iFrame and Javascript actions

I'll post my code below. My goal is to grab the selected text in an
iFrame from javascript (really any way possible). When I highlight
text in the iFrame and click the link outside of the iFrame, I receive
the following error:

Firefox FireBug Error
uncaught exception: Permission denied to get property
HTMLDocument.ge tSelection

IE7 Error
Error: Access Denied.
Line: 25

If you have any idea what is going wrong, then I urge you to reply to
my post. If you have another way to do what way, then I also urge you
to reply. Thank you very much for taking the time to read through my
post.

<html>
<head>
<title>Title of page</title>

<!-- Include CSS Files -->
<link rel="stylesheet " href="style.css " />

<!-- Include JS Files -->
<script type="text/javascript" src="prototype. js"></script>
<script type="text/javascript" src="mootools.v 1.00.js"></script>

<script>
function showFxTarget(ta rget) {
$(target).makeD raggable();
$(target).setSt yles({
'display': 'block',
'visibility':'v isible'
});

if (document.getSe lection) {
var iframe = window.frames.g roups;
var str = iframe.document .getSelection() ;
} else if (document.selec tion && document.select ion.createRange ) {
var iframe = window.frames.g roups;
var range = iframe.document .selection.crea teRange();
var str = range.text;
} else {
var str = "Error: Could not find the selected text.";
}

}
</script>
</head>
<body>
<h2>A draggable box</h2>
<div id="firstFXT" class="fxTarget "></div>
<p>Click <a href="javascrip t:showFxTarget( 'firstFXT');">h ere</a>to
make the box appear.</p>
<iframe name="groups" frameborder="0" src ="http://groups.google.c om/"
width="80%">
<div id="firstFXT" class="fxTarget "></div>
</iframe>
</html>

Apr 27 '07 #1
5 7708
On Apr 26, 9:25 pm, brad <bradfo...@gmai l.comwrote:
I'll post my code below. My goal is to grab the selected text in an
iFrame from javascript (really any way possible). When I highlight
text in the iFrame and click the link outside of the iFrame, I receive
the following error:

Firefox FireBug Error
uncaught exception: Permission denied to get property
HTMLDocument.ge tSelection

IE7 Error
Error: Access Denied.
Line: 25

If you have any idea what is going wrong, then I urge you to reply to
my post. If you have another way to do what way, then I also urge you
to reply. Thank you very much for taking the time to read through my
post.
You cannot do what you want to do. The JavaScript in your page cannot
access the contents of the iframe served from a different domain. I am
assuming your page is not being served from groups.google.c om since
you are seeing the access denied error.

Peter

<html>
<head>
<title>Title of page</title>

<!-- Include CSS Files -->
<link rel="stylesheet " href="style.css " />

<!-- Include JS Files -->
<script type="text/javascript" src="prototype. js"></script>
<script type="text/javascript" src="mootools.v 1.00.js"></script>

<script>
function showFxTarget(ta rget) {
$(target).makeD raggable();
$(target).setSt yles({
'display': 'block',
'visibility':'v isible'
});

if (document.getSe lection) {
var iframe = window.frames.g roups;
var str = iframe.document .getSelection() ;
} else if (document.selec tion && document.select ion.createRange ) {
var iframe = window.frames.g roups;
var range = iframe.document .selection.crea teRange();
var str = range.text;
} else {
var str = "Error: Could not find the selected text.";
}

}

</script>
</head>
<body>
<h2>A draggable box</h2>
<div id="firstFXT" class="fxTarget "></div>
<p>Click <a href="javascrip t:showFxTarget( 'firstFXT');">h ere</a>to
make the box appear.</p>
<iframe name="groups" frameborder="0" src ="http://groups.google.c om/"
width="80%">
<div id="firstFXT" class="fxTarget "></div>
</iframe>
</html>

Apr 27 '07 #2
That's right I am serving the page from a different domain. Are you
saying that it is impossible to accomplish with Javascript? If so,
then do you have an suggestions on other avenues to pursue? Thank you
very much for your replies.

Apr 27 '07 #3
On Apr 26, 9:36 pm, brad <bradfo...@gmai l.comwrote:
That's right I am serving the page from a different domain. Are you
saying that it is impossible to accomplish with Javascript?
It is impossible. This is a JavaScript security restriction.
If so, then do you have an suggestions on other avenues to pursue?
Load the Google groups page onto the server. Serve the page from your
server to the browser. Get sued by Google for copyright infringement.

Peter

Apr 27 '07 #4
Alright. Well I don't want to be sued by Google. They may be looking
for people to sue to cover their YouTube charges if they don't get
that worked out in a few years. Thanks for you help Peter.

Apr 27 '07 #5
What you're trying to do is called "cross-site scripting", and it's a
known security exposure so, it's typically prevented. Google for that
phrase and READ ALL ABOUT IT! HTH.

Apr 27 '07 #6

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

Similar topics

2
2717
by: Gord | last post by:
Hello, I have some ASP / HTML webpages using an iframe to function as a Content Editor which works fine in IE. It has javascript preforming actions on the iframe content, such as putting the text in bold, creating hyper links etc.. However none of this works in Opera or Netscape, is this totally impossible? Thanks for any help.
3
9517
by: Paul | last post by:
HI! how do we load a page from the menu into an iframe when you are not on the iframe page? I want to be able to load pages (options in my menu ) into a iframe no matter if I am on the iframe page or not. how do we do this. Right I have two menu's because I dont know how to do this. one for other pages that dont have the iframe in question and another for the
16
7118
by: Mcginkel | last post by:
I am trying to find a way to load XHTML content in an Iframe. I use to do this in html by using the following code : var iframeObject = document.createElement("iframe"); MyDiv.appendChild(iframeObject); var data = "<html><head><title>testing</title></head><body>data</body></html>" iframeObject.contentDocument.open(); iframeObject.contentDocument.writeln(data);
4
28011
by: christine.nguyen | last post by:
Hello, Here's the deal. I have an html page that contains an iframe. This iframe has an id that is unknown to me. This iframe also has test.html as it's source. Within test.html runs some javascript. Within this javascript that runs in test.html, I want to obtain the id of the iframe that loaded test.html in the first place. Is this possible?? I have no control over the iframe at all. The iframe will be loaded on some random html...
3
9564
by: Timo | last post by:
In javascript code on MyPage.aspx, I set a hidden IFRAME's source url: myframe.location.href = 'someotherpage.aspx'; If the session has timed out, preventing someotherpage.aspx from being loaded into the IFRAME, where can that error condition be trapped? Thanks Timo
13
6717
by: ukrbend | last post by:
I'm new to Javascript and to html and am trying to make the following code snippet work but it doesn't. It refuses to call the getPage() function and I always get a 404 error. I know the code is getting as far as the iframe section as other parts of the html code work correctly. But it is not executing any code within the getPage() function as some "hello world" writes within getPage() wouldn't print. ...
18
43567
by: Chris Ianson | last post by:
Hi geniuses (or is that genii, or genies) The challenge is as above really. I have a page with an iframe in it, and need to call a JS function in the *parent* page, *from* inside the iframe. (It's for Google Maps, but I won't bore you with the complexities of that, as it doesn't affect the question). Mochas kudos to anyone able to solve this widdle.
3
4489
by: PCgeek | last post by:
sorry moved this over to javascript forum, didn't mean to post 2x! Hi guys, I'm trying to put the finishing touches on my website and could really use some help on this particular issue. My page includes background music with a javascript music player on the main page below an iframe that is used for all content and navigation of the site and so that the music doesn't reload each time a page is switched. There is another javascript to resize...
1
4919
by: cdmsenthil | last post by:
I have an Infragistics UltrawebGrid . Each Row in the grid is attached to a context menu using Infragistics CSOM Upon click on the menu, I am creating an Iframe dynamically which points to another page in the same domain which also contains infragistics datagid populated with default data retrieved from Data Base. After creating the frame I am attaching it to the HTML DOM and show it as modal popup with OK and Cancel Button inside an...
0
9535
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
10467
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
10244
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
10201
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,...
1
7558
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
6802
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4130
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
3744
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.