By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,739 Members | 1,506 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,739 IT Pros & Developers. It's quick & easy.

iFrame and Javascript actions

P: n/a
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.getSelection

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.v1.00.js"></script>

<script>
function showFxTarget(target) {
$(target).makeDraggable();
$(target).setStyles({
'display': 'block',
'visibility':'visible'
});

if (document.getSelection) {
var iframe = window.frames.groups;
var str = iframe.document.getSelection();
} else if (document.selection && document.selection.createRange) {
var iframe = window.frames.groups;
var range = iframe.document.selection.createRange();
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="javascript:showFxTarget('firstFXT');">here</a>to
make the box appear.</p>
<iframe name="groups" frameborder="0" src ="http://groups.google.com/"
width="80%">
<div id="firstFXT" class="fxTarget"></div>
</iframe>
</html>

Apr 27 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On Apr 26, 9:25 pm, brad <bradfo...@gmail.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.getSelection

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.com 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.v1.00.js"></script>

<script>
function showFxTarget(target) {
$(target).makeDraggable();
$(target).setStyles({
'display': 'block',
'visibility':'visible'
});

if (document.getSelection) {
var iframe = window.frames.groups;
var str = iframe.document.getSelection();
} else if (document.selection && document.selection.createRange) {
var iframe = window.frames.groups;
var range = iframe.document.selection.createRange();
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="javascript:showFxTarget('firstFXT');">here</a>to
make the box appear.</p>
<iframe name="groups" frameborder="0" src ="http://groups.google.com/"
width="80%">
<div id="firstFXT" class="fxTarget"></div>
</iframe>
</html>

Apr 27 '07 #2

P: n/a
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

P: n/a
On Apr 26, 9:36 pm, brad <bradfo...@gmail.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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.