iFrame and Javascript actions

B

brad

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>
 
P

Peter Michaux

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
 
B

brad

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.
 
P

Peter Michaux

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
 
B

brad

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.
 
A

ashore

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top