Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Gecko browsers + iframe + selection. 1

Status
Not open for further replies.

LordGarf

Programmer
Apr 13, 2005
34
BE
Hi,

I managed to create a wysiwyg editor for both mozilla FF and IE.
There is only one problem left and that is my link insertor.

I do not use the standard link insertor of the execCommand.
I use a self written one.

It works perfectly in IE.

for example you select text in the editor (wich is an iframe) you press the link button. A pop up shows up with a few fields.
First field you have to type in the URL. And onother field where you can give your linke a name. if you did select text this name will be the selected text and will be used to wrap arround the a tags that link to the URL. leave it blank and you will see te URL as a link. You can also fill it in manualy.

now I want the same to work in Firefox but I tried lots and lots of things. So my question is:

How to get the content of a selection in an iframe with mozilla??
and how to replace it??

tank you,

best regards,
Lord_Garfield
 

I think you can use the getSelection() method of the iframe's window:

Code:
<html>
<head></head>
<body>
	<iframe id="myIframe" src="yourpage.html"></iframe>
	<input type="button" value="Get Selection" onclick="alert(document.getElementById('myIframe').contentWindow.getSelection());" />
	Lorum ipsum dolor sit amet...
</body>
</html>

Remember: this is Firefox (Gecko) code only... I dont' think it will work in IE.

Hope this helps,
Dan


[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
this is my code

<code>
function fill_exlinkn()
{
var ua = navigator.userAgent.toLowerCase();
isFF = (ua.indexOf("gecko") != -1);
if (!isFF)
{
selection = window.opener.frames[naam].document.selection.createRange();
exlinknaam = selection.text;
}
else
{
s = window.opener.frames[naam].document.body.innerHTML;
//window.opener.document.getElementById(naam).contentWindow.focus();
selection = window.opener.frames[naam].contentWindow.getSelection();
//selection = window.opener.document.getElementById(naam).contentWindow.getSelection();
exlinknaam = selection;
}
document.form1.exlinkn.value = exlinknaam;
}
function submit_link()
{
if (document.form1.exlinkn.value == "")
{
exlink = "<a href=" + form1.link_type.value + form1.exlink.value + " target=_blanc>" + form1.exlink.value + "</a>";
}
else
{
exlink = "<a href=" + form1.link_type.value + form1.exlink.value + " target=_blanc>" + form1.exlinkn.value + "</a>";
}
if (!isFF)
{
window.opener.frames[naam].focus();
selection.pasteHTML(exlink);
}
else
{
window.opener.document.getElementById(naam).contentWindow.focus();
window.opener.document.getElementById(naam).contentWindow.getSelection().pasteHTML(exlink);
}
window.close();
}
</code>

tank you,

best regards,
Lord_Garfield
 
hmm sorry to double post but I don't find a way to edit the message.

It is espacialy the function submit link that needs to work in FF. the other function works if you comment it and uncomment the parts in comment.. I was to fast pasting it..

Here is the working fill_exlinkn() function.
Code:
function fill_exlinkn()
{
 	var ua = navigator.userAgent.toLowerCase();
	isFF = (ua.indexOf("gecko") != -1);
	if (!isFF)
	{
 	selection = window.opener.frames[naam].document.selection.createRange();
  exlinknaam = selection.text;
	}
	else
	{
	//s = window.opener.frames[naam].document.body.innerHTML;
	//window.opener.document.getElementById(naam).contentWindow.focus();
	//selection = window.opener.frames[naam].contentWindow.getSelection();
	selection = window.opener.document.getElementById(naam).contentWindow.getSelection();
	exlinknaam = selection;
	}
	document.form1.exlinkn.value = exlinknaam;
}

tank you,

best regards,
Lord_Garfield
 
After looking through the nsISelection docs on Mozilla's website:


it looks like there is no "pasteHTML" method... in fact it looks like there is no way to paste at all.

Hope this helps,
Dan


[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]
 
any alternatives then?

tank you,

best regards,
Lord_Garfield
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top