-->
Hướng dẫn sửa lỗi reply (trả lời) comment blogspot

Hướng dẫn sửa lỗi reply (trả lời) comment blogspot


Gần đây một số blog bị lỗi không trả lời (reply) comment được trên blog của mình, hóng mãi mới có cao nhân sữa được lỗi này. Cách này vừa sữa lỗi vừa tối ưu bớt js, được hướng dẫn bởi blog Hưng Hoàng Văn (Hung1001). Các bạn cùng xem hướng dẫn nhé.
Niemstyle | Hướng dẫn sửa lỗi reply (trả lời) comment blogspot
Đầu tiên: Tích hợp jQuery (nếu blog chưa có): dán sau thẻ <head>
<script src='//cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js' type='text/javascript'></script>

1. Sữa lỗi reply comment đối với Blog1 version 1

Tìm đến thẻ <b:includable id='threaded_comment_js' var='post'> và thay toàn bộ nội dung bên trong nó thành:
<script type='text/javascript'>//<![CDATA[
$(function() {
    const t = $("#comment-editor-src").attr("href");
    $(".comment-reply").each(function() {
        var e = $(this);
        e.on("click", function(n) {
            $(".comment-actions").show(), n.preventDefault();
            let r = e.parents("li").attr("id").substr(1),
                c = t.split("?");
            $("#comment-editor")[0].src = c[0] + "?parentID=" + r + "&" + c[1], e.parent().hide(), e.parents("li").append($(".comment-form")[0])
        })
    })
});
//]]></script>

2. Sữa lỗi reply comment đối với Blog1 version 2

Tìm đến thẻ <b:includable id='threadedCommentJs' var='post'> và thay toàn bộ nội dung bên trong nó thành:
<script>//<![CDATA[
$(function() {
    const t = $("#comment-editor-src").attr("href");
    $("a[o='r']").each(function() {
        var n = $(this);
        n.on("click", function(e) {
            $(".comment-actions").show(), e.preventDefault();
            let o = n.parents(".comment-block").attr("id").substr(1),
                c = t.split("?");
            $("#comment-editor")[0].src = c[0] + "?parentID=" + o + "&" + c[1], n.parent().hide(), n.parents("li").append($(".comment-form")[0])
        })
    })
});
//]]></script>
Chỉ mấy bước đơn giản vậy thôi, blog mình version 1 cũng bị lỗi và đã fix được ở bước 1.

Cập nhật: áp dụng chung cho Ver1Ver2
<script type='text/javascript'>//<![CDATA[
$(window).on("load", function() {
  function n(n, t) {
    $(n).each(function() {
      var n = $(this);
      n.on("click", function(e) {
        $(".comment-actions,.cancel-comment").show(), e.preventDefault();
        let c = n.parents(t).attr("id").substr(1),
          m = o.split("?");
        $("#comment-editor")[0].src = m[0] + "?parentID=" + c + "&" + m[1], n.parent().hide(), n.parents("li").append($(".comment-form")[0])
      })
    })
  }
  $(".comment-form").append('<a class="cancel-comment" style="font-family:Roboto,sans-serif;font-weight:700;font-size:12px;color:#ff0000;cursor:pointer;">CANCEL</a>'), $(".cancel-comment").hide();
  const o = $("#comment-editor-src").attr("href");
  $(".comment-block[id]").length ? n("a[o='r']", ".comment-block") : n(".comment-reply", "li"), $(".cancel-comment").on("click", function() {
    $(".comment-actions").show(), $("#comment-editor")[0].src = o, $(".comments-content").before($(".comment-form")[0]), $(this).hide()
  })
});
//]]></script>
  1. Replies
    1. Chỉ tạm thời thôi, thời gian sau nó chẳng có tác dụng gì.

      Delete
    2. Cái này tùy cấu trúc template, có khi blog1 v2 nhưng dữ liệu <data:post.commentHtml/> trả về mã html v1 và ngược lại, thì mình phải đổi selector. trong tương lai nếu blogger cập nhật lên v mới mà mình không upgrade thì code vẫn chạy đúng. à mà đã có code js tối ưu cho cả v1 v2 rồi nhé dán một phát là xong không cần phân biệt nữa

      Delete
    3. Đã xem bên blog ông rồi.

      Delete
  2. anh niệm qua xem cái temp em responsive sao nó k hiển thị dấu 3 chấm ở cuối tiêu đề... :< chỉ em với

    ReplyDelete
    Replies
    1. Cái chỗ phần res, e thêm thuộc tính giống như hiện ở PC là đc mà.

      Delete
  3. Hôm bữa gặp temp đẹp bị nz bh mới thấy bài anh :(

    ReplyDelete
  4. E cũng hay bị như vậy lắm để test thử xem 😖

    ReplyDelete
  5. Replies
    1. Có một số temp nó ko bị cũng chả hiểu.

      Delete
  6. Chưa biết nguyên nhân vì sao nhưng cứ bookmark bài này của ông lại đã, mẹ cha thằng blog suốt ngày lỗi tào lao

    ReplyDelete
    Replies
    1. hồi tháng 10 blog nó thay đổi nhiều thứ mà bọn mình nqu quá chả biết nổi :v

      Delete
  7. Sao h cập nhật mà k đc n ạ :s n có thể fix giúp h đc k?

    ReplyDelete
  8. lâu rồi mới vào bối rối quá kaka

    ReplyDelete
  9. cảm ơn bác, em làm đc rồi

    ReplyDelete

Đăng ký bản tin

Đăng ký email để không bỏ lỡ những bài viết hay