2016-09-10 9 views
0

FirefoxとInternet Explorerの両方で動作するようにコードを管理しました。私の質問は、単語が選択されたときにどのようにハイライトの色を変更するのですか?現在、ユーザーのブラウザに基づいてデフォルトのハイライトを使用しています(青色)。私が得た場合どのようにハイライトの色を変更しますか?

<table border="0" cellpadding="0" cellspacing="0"> 
<tbody><tr><td valign="top" width="568"> 

<h3><font face="Verdana,Arial,Helvetica,sans-serif" color="#000099"> 
Searching for text on the current page 
</font></h3> 

<table border="0" cellpadding="1" cellspacing="1"><tbody><tr><td valign="top"><iframe id="srchform" src="search_form.html" border="0" scrolling="no" frameborder="0" height="50" width="220"> 
</iframe> 

</td><td style="padding-top:3px;" valign="top" width="99"></td> 
</tr></tbody></table> 
<p></p> 
<p>this a test this a test this a test this a test this a test this a test this a test this a test this a test this a test</p> 
<p>this a test this a test this a test this a test this a test this a test this a test this a test this a test this a test</p> 
<p>this a test this a test this a test this a test this a test this a test this a test this a test this a test this a test</p> 
<p>this a test this a test this a test this a test this a test this a test this a test this a test this a test this a test</p> 
<p>this a test this a test this a test this a test this a test this a test this a test this a test this a test this a test</p> 
<p>this a test this a test this a test this a test this a test this a test this a test this a test this a test this a test</p> 
<p>this a test this a test this a test this a test this a test this a test this a test this a test this a test this a test</p> 
<p>this a test this a test this a test this a test this a test this a test this a test this a test this a test this a test</p> 
<p>this a test this a test this a test this a test this a test this a test this a test this a test this a test this a test</p> 

<script language="Javascript"> 
var TRange=null; 

function findString (str) { 
if (parseInt(navigator.appVersion)<4) return; 
var strFound; 
if (window.find) { 


    strFound=self.find(str); 
    if (!strFound) { 
    strFound=self.find(str,0,1); 
    while (self.find(str,0,1)) continue; 
    } 
} 
else if (navigator.appName.indexOf("Microsoft") != -1 || navigator.appName.toString().toUpperCase()== "NETSCAPE") { 
      // EXPLORER-SPECIFIC CODE 
      if (TRange != null) { 
       TRange.collapse(false); 
       strFound = TRange.findText(str); 
       if (strFound) TRange.select(); 
      } 
      if (TRange == null || strFound == 0) { 
       TRange = self.document.body.createTextRange(); 
       strFound = TRange.findText(str); 
       if (strFound) TRange.select(); 
      } 
     } 
     else if (navigator.appName == "Opera") { 
      alert("Opera browsers not supported, sorry...") 
      return; 
     } 
     if (!strFound) alert("String '" + str + "' not found!") 
     return; 
    } 
</script> 

、ここで「検索」をユーザーがクリックするとsearch_form.htmlのコード(上からのiframe)

<form id="f1" name="f1" action="javascript:void()" onsubmit="if(this.t1.value!=null &amp;&amp; this.t1.value!='') 
parent.findString(this.t1.value);return false;"> 
<input id="t1" name="t1" value="text" size="20" type="text"> 
<input name="b1" value="Find" type="submit"> 
</form> 
+0

IEで動作させることができました。 – user3683976

答えて

0

があるとき、私は黄色のハイライトを使用できるようにしたいですあなたの質問の権利、これはあなたが探しているものです:selections。 Css-trickはそれについての素晴らしいチュートリアルを手に入れました。 ::selectionセレクタがすべてのブラウザと互換性がないため、ブラウザのサポートも確認する必要があります

+0

これは私が笑を探していたものです。ありがとう兄貴。 – user3683976

関連する問題