A
Alexander Higgins
Hi,
I am using the contentwindow.find function to insert hyperlinks into a
Dhtml iframe rich text editor. I have been able to accomplish what I
need to in IE, but am having problems in firefox. Basically, I an
using the execCommand("createLink") to insert hyperlinks.
To find the hyperlink in firefox, I am using contentWindow.Find to
select the hyperlink before using the create link. The problem is that
after using contentWindow.find, and subsequent calls to the function
begin the search after the current selection and not at the beginning
of the Iframe document body.
A short version of the code I am using is below. I create the iframe
and write the alphabet to it. Then If i search for the letter a it
will find it. If I search for b it will find it. But After I have
searched for B, it will not longer find a as evert find after this will
start at the letter b.
How do I reset the contentWindow.find back to the beginning of the
Iframe, without rewriting the contents of the entire I frame document??
Here's the code to reproduce the issue. Be advised that
contentWindow.find does not work in IE, In IE I use the follwing code,
which works fine.
body.createTextRange();
sText.findText("Term I am Searching for");
sText.select();
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>fffind</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
<script type=text/javascript>
function init(){
var tmp = document.getElementById("fr");
var win=tmp.contentWindow;
var obj=tmp.contentWindow.document;
obj.designMode="On";
obj.open();
obj.write('a b c d e f g h i j k l m n o p q r s t u v w x y z');
obj.close();
}
function findit(){
var tmp = document.getElementById("fr");
var win=tmp.contentWindow;
var obj=tmp.contentWindow.document;
var sTerm=document.getElementById("term")
sText = obj.createRange();
sText.selectNode(sTerm);
content=sText.toString();
// obj.contentWindow.find(website.innerHTML);
//alert(content);
tmp.contentWindow.find(sTerm.value);
}
</script>
</HEAD>
<body MS_POSITIONING="FlowLayout" onload="init();">
<form id="Form1" method="post" runat="server">
<iframe src="javascript:void(0);" id="fr" width=200
height=100></iframe>
<p>enter a term to find<BR>
<INPUT type="text" id="term"><INPUT type="button" value="Find it."
onclick="findit();">
<br>
</p>
</form>
</body>
</HTML>
With this code, If I type b into the term text box and click find, it
will find the letter b. But if i type a in after that it will not find
it. It will find any letter after the b. How do you reset the
window.find back to the beginning of the document.
An addiotional note. If I put the code for the init function inside of
the findit function then the findit starts at the beginning of the
document. However , I don't think this is an option. As the contents
of the real Iframe I am using is another web page wich is actually
quite long, and contains javascript and server side .Net code.
Thanks again.
I am using the contentwindow.find function to insert hyperlinks into a
Dhtml iframe rich text editor. I have been able to accomplish what I
need to in IE, but am having problems in firefox. Basically, I an
using the execCommand("createLink") to insert hyperlinks.
To find the hyperlink in firefox, I am using contentWindow.Find to
select the hyperlink before using the create link. The problem is that
after using contentWindow.find, and subsequent calls to the function
begin the search after the current selection and not at the beginning
of the Iframe document body.
A short version of the code I am using is below. I create the iframe
and write the alphabet to it. Then If i search for the letter a it
will find it. If I search for b it will find it. But After I have
searched for B, it will not longer find a as evert find after this will
start at the letter b.
How do I reset the contentWindow.find back to the beginning of the
Iframe, without rewriting the contents of the entire I frame document??
Here's the code to reproduce the issue. Be advised that
contentWindow.find does not work in IE, In IE I use the follwing code,
which works fine.
body.createTextRange();
sText.findText("Term I am Searching for");
sText.select();
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>fffind</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
<script type=text/javascript>
function init(){
var tmp = document.getElementById("fr");
var win=tmp.contentWindow;
var obj=tmp.contentWindow.document;
obj.designMode="On";
obj.open();
obj.write('a b c d e f g h i j k l m n o p q r s t u v w x y z');
obj.close();
}
function findit(){
var tmp = document.getElementById("fr");
var win=tmp.contentWindow;
var obj=tmp.contentWindow.document;
var sTerm=document.getElementById("term")
sText = obj.createRange();
sText.selectNode(sTerm);
content=sText.toString();
// obj.contentWindow.find(website.innerHTML);
//alert(content);
tmp.contentWindow.find(sTerm.value);
}
</script>
</HEAD>
<body MS_POSITIONING="FlowLayout" onload="init();">
<form id="Form1" method="post" runat="server">
<iframe src="javascript:void(0);" id="fr" width=200
height=100></iframe>
<p>enter a term to find<BR>
<INPUT type="text" id="term"><INPUT type="button" value="Find it."
onclick="findit();">
<br>
</p>
</form>
</body>
</HTML>
With this code, If I type b into the term text box and click find, it
will find the letter b. But if i type a in after that it will not find
it. It will find any letter after the b. How do you reset the
window.find back to the beginning of the document.
An addiotional note. If I put the code for the init function inside of
the findit function then the findit starts at the beginning of the
document. However , I don't think this is an option. As the contents
of the real Iframe I am using is another web page wich is actually
quite long, and contains javascript and server side .Net code.
Thanks again.