Hiển thị mã HTML tại comment blogger

Comment blogger có thể hiển thị code HTML bởi vậy bạn cần phải mã hóa code HTML này trước khi muốn chú thích cho ai đó một đoạn code nào :

Mã HTML được hiển thị trên comment thông qua bộ mã hóa


Ví dụ :

<p><b>Đây là một code HTML hiển thị như text</b></p>

Bạn cũng muốn code trên hiển thị như vậy thì bạn phải mã hóa trước khi post vào comment để có được hiển thị như trên.



Mời mọi người xem qua DEMO :


Để có thể thêm vào ngay bên trên Comment-Editor của blogger bạn thực hiện theo hướng dẫn sau :

Bước 1 : Search với code : </head> . Thêm ngay trước đó Jquery.min (nếu bạn đã có thì bỏ qua):

<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js' type='text/javascript'/>

Bước 2: Search với code : </body> . Thêm ngay trước đó :

<!-- JS by http://www.erhay.com -->
<script type='text/javascript'>
    //<![CDATA[
    function insert_CODE() {
        var HTMLElement = document.getElementById("html");
        var reGT = />/gi;
        var reLT = /</gi;
        var reAMP = /&/gi;
        var reDQUOTE = /"/gi;
        var reQUOTE = /'/gi;
        var strXML = HTMLElement.value.replace(reAMP, "&amp;").replace(reLT, "&lt;").replace(reGT, "&gt;").replace(reDQUOTE, "&quot;").replace(reQUOTE, "&#039;");
        document.getElementById("html").value = strXML;
    }
    //]]>
</script>
<script type='text/javascript'>
    //<![CDATA[
    var textBox = document.getElementById("html");
    textBox.onfocus = function () {
        textBox.select();
        // Work around Chrome's little problem
        textBox.onmouseup = function () {
            // Prevent further mouseup intervention
            textBox.onmouseup = null;
            return false;
        };
    };
    function SelectText(element) {
        var doc = document,
            text = doc.getElementById(element),
            range, selection;
        var _0xba07 = ["\x63\x72\x65\x61\x74\x65\x54\x65\x78\x74\x52\x61\x6E\x67\x65", "\x62\x6F\x64\x79", "\x6D\x6F\x76\x65\x54\x6F\x45\x6C\x65\x6D\x65\x6E\x74\x54\x65\x78\x74", "\x73\x65\x6C\x65\x63\x74", "\x67\x65\x74\x53\x65\x6C\x65\x63\x74\x69\x6F\x6E", "\x63\x72\x65\x61\x74\x65\x52\x61\x6E\x67\x65", "\x73\x65\x6C\x65\x63\x74\x4E\x6F\x64\x65\x43\x6F\x6E\x74\x65\x6E\x74\x73", "\x72\x65\x6D\x6F\x76\x65\x41\x6C\x6C\x52\x61\x6E\x67\x65\x73", "\x61\x64\x64\x52\x61\x6E\x67\x65"];
        if (doc[_0xba07[1]][_0xba07[0]]) {
            range = document[_0xba07[1]][_0xba07[0]]();
            range[_0xba07[2]](text);
            range[_0xba07[3]]();
        } else {
            if (window[_0xba07[4]]) {
                selection = window[_0xba07[4]]();
                range = document[_0xba07[5]]();
                range[_0xba07[6]](text);
                selection[_0xba07[7]]();
                selection[_0xba07[8]](range);
            };
        };
    }
    $(function () {
        $('blockquote').click(function () {
            SelectText('selectme');
        });
    });
    $("input[type='button']").click(function () {
        $('textarea').focus();
        $('textarea').select(); //select text inside
    });
    //]]>
</script>
<!-- HTML mã hóa để comment blogger -->

Bước 3: Đặt khung mã hóa ngay trước Comment như Demo.

Nhấn Ctrl + F để search với khóa : <a expr:href='data:post.commentFormIframeSrc' id='comment-editor-src'/>

Bạn sẽ tìm được 4 khóa trên :

Thêm vào sau khóa vị trí thứ 2 và thứ 4 code sau :

 <!-- HTML mã hóa để comment blogger -->
      <textarea style="height:50px; width:250px" id="html">Dán code HTML để Post vào comment </textarea>
<br/>
      <input style="background:#f7f8f9; border-radius:4px" class="button" type="button" onclick="insert_CODE();" value="Xử lý code"/>
(M. Anh - Erhay)

Chúc bạn thực hiện thành công hướng dẫn trong bài viết này. Vui lòng ghi rõ nguồn Erhay khi bạn phát hành thông tin từ trang này. Mọi ý kiến đóng góp bạn vui lòng comment.
Nguồn : chúng tôi sưu tầm từ nhiều nguồn
SHARE

Thiết kế web chuyên nghiệp giá rẻ

Chúng tôi tuyên thiết kế web chuyên nghiệp đẳng cấp giá rẻ với 5 năm kinh nghiệm trong lĩnh vực thiết kế website nếu các bạn có nhu cầu có thể liên hệ Hotline: 0962 66 57 57 || Email: cmay.tt@gmail.com || website: cmay.vn

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 nhận xét:

Đăng nhận xét