突出显示选定的文本并在下次显示 [英] Highlight selected text and show next time

查看:94
本文介绍了突出显示选定的文本并在下次显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户在网页上的任何地方选择必须突出显示文本并必须将其另存为字符串的数据库时,我对保存文本感兴趣.
当同一用户下次看到同一页面时,必须像以前一样突出显示文本.
如果有人知道一种简单而优雅的方法,我将不胜感激,但是在这一点上,我将采取任何解决方案.即使您能指出正确的方向,也将不胜感激.预先感谢.

I am interested in saving text when user selects any text anywhere on a web page that text has to be highlighted and has to save that text as a string in DataBase.
when same user saw same page next time text has to be highlighted as done previously by him.
If anyone knows a simple elegant way to do this I would really appreciate it, but I''ll take any solution at this point. Even if you can point me in the right directions that would be appreciated. Thanks in advance.

推荐答案



我尝试了这段代码,效果很好.请尝试一次

如果使用Jquery,则可以将捕获文本传递到服务器.


Hi,

I tried this code it works fine.Try once

If you use Jquery you can pass capture text to server.


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script language ="javascript" >
 
        document.onselectstart = df;
        document.onmouseup = dfu;

        function dfu(event) {
            document.getElementById("showtextid").innerHTML = "selection ended the selected text is   :   " + document.selection.createRange().text+"";
        }
        function df(event) {
            document.getElementById("showtextid").innerHTML = "selection started" ;

        }
      
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
       <div id="showtextid"></div><br />
       this is just for testing

       I am interested in saving text when user selects any text anywhere on a web page that text has to be highlighted and has to save that text as a string in C#.
when same user saw same page next time text has to be highlighted as done previously by him.
If anyone knows a simple elegant way to do this I would really appreciate it, but I'll take any solution at this point. Even if you can point me in the right directions that would be appreciated. Thanks in advance.
    </div>
    </form>
</body>
</html>


如果您使用的是Jquery,则没问题.

我希望你能理解我的所作所为

使用


If you are using Jquery then no problem.

I hope you understood what I did

Use


.post()将选定的数据发布到服务器并保存在数据库中.


一切顺利.
.post() to post selected data to server and save in database .



All the Best.


感谢您的答复,但除了IE之外,其他方法均不起作用.

我尝试使用此代码

Thanks for your reply but it will not work other than IE .

I m tried with this code

function highlight() {
           var range, sel;
           // IE case
           if (document.selection && document.selection.createRange) {
               range = document.selection.createRange();
               //range.execCommand("Bold", false, null);
               range.execCommand("BackColor", "false", "yellow");
               txt = document.selection.createRange().text;
           } else if (window.getSelection) {
               // Non-IE
               sel = window.getSelection();
               if (sel.rangeCount && sel.getRangeAt) {
                   range = sel.getRangeAt(0);
                   alert(range);
               }
               document.designMode = "on";
               if (range) {
                   sel.removeAllRanges();
                   sel.addRange(range);
                   alert(range);
               }
               // document.execCommand("Bold", false, null);
               document.execCommand("BackColor", "false", "yellow");
               document.designMode = "ofx  f";
           }
       }
   </script>


但是使用此代码在firefox中出现问题,但在IE,Chrome中运行良好,并且当同一用户下次打开同一页面时,我也显示了突出显示的文本.为此,我必须将文本存储在数据库中.


but using this code i m getting problem in firefox but it works fine in IE,Chrome and also i have show highlight the text when same user open same page next time For that i have to store text in my database.


这篇关于突出显示选定的文本并在下次显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆