...

View Full Version : displaying highlighted text from an inline page



tpeck
12-12-2006, 11:42 AM
I have a short script which will instantly copy highlighted text on a page and have it display in a form button:

<form name=theform>
Selected text: <input type=text name=text value="">
</form>

It works well - here is the code:


var text = "";
function getActiveText(e) {

// Sets text MSIE or Netscape active
// text based on browser, puts text in form
text = (document.all) ? document.selection.createRange().text : document.getSelection();

document.theform.text.value = text;
return true;
}

document.onmouseup = getActiveText;
if (!document.all) document.captureEvents(Event.MOUSEUP);

My problem is that I need to highlight text within an inline frame on the page, not on the page itself, and have it display in the form button.

What should I alter in the script to make this happen? Am I asking the impossible; I don't think it would be if I knew how to reference the inline code page from this page.

Thanks

Arty Effem
12-13-2006, 01:04 AM
I have a short script which will instantly copy highlighted text on a page and have it display in a form button:


My problem is that I need to highlight text within an inline frame on the page, not on the page itself, and have it display in the form button.

What should I alter in the script to make this happen? Am I asking the impossible; I don't think it would be if I knew how to reference the inline code page from this page.

You need to place the code inside the framed document (which must be on the same domain).
Try this script, replacing the bold text with the name of the form and the element to receive the text.


<SCRIPT type='text/javascript'>

function getActiveText(elem)
{
elem.value = (document.selection && document.selection.createRange) ?
document.selection.createRange().text :
document.getSelection?
document.getSelection():
"";

return true;
}

if(document.captureEvents)
document.captureEvents(Event.MOUSEUP);
document.onmouseup = function(){getActiveText( parent.document.forms.myFormName.elementName );}

</SCRIPT>

tpeck
12-13-2006, 04:37 AM
Wonderful! Thanks so much. You have shown it's possible. I can follow some of the code you supplied.

Now I have to take it a little further. I now know the text can be displayed from the inline to the parent page, but I need to display it to another frame.

I tried substituting the frame name for "parent" in the code but no luck.

I also have to do this three times on a page. Here is a demo (sorry about the colour scheme!):

http://aapress.com.au/demo/hilite/hilite.html

When I get this right, I have to duplicate the entire structure 1000 times, so it would be helpful if the code was only in one place instead of the three inline frames, but I don't think that is likely.

At the moment, if I can just get the blue text to display in the blue textbox bottom of the page I'll be very happy.

(I've left the working example you supplied on the top frame - to demonstrate that it works).

Thanks again.

Arty Effem
12-13-2006, 03:32 PM
I tried substituting the frame name for "parent" in the code but no luck.

I also have to do this three times on a page. Here is a demo (sorry about the colour scheme!):

http://aapress.com.au/demo/hilite/hilite.html

When I get this right, I have to duplicate the entire structure 1000 times, so it would be helpful if the code was only in one place instead of the three inline frames, but I don't think that is likely.

At the moment, if I can just get the blue text to display in the blue textbox bottom of the page I'll be very happy.

(I've left the working example you supplied on the top frame - to demonstrate that it works).

Thanks again.

The form tags in the target document aren't closed.

Use: parent.parent.main.document.forms.q2.hilite2

tpeck
12-14-2006, 07:07 AM
Now why didn't I think of that? (don't answer!)

How you reference windows/frames accurately has always eluded me. I mean, I get the drift, but I can't get the full hang of it.

I've updated the demo to include all your fixes, and it is a joy to behold.

Many thanks indeed!

Terry



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum