Code hiển thị thông báo khi mất kết nối mạng cho Website/Blogspot
Chào các bạn, Điều này sẽ rất thú vị khi thông báo cho khách truy cập của bạn về kết nối internet. Nếu khách truy cập đang xem nội dung trang web của bạn và không may kết nối internet bị ngắt, nó sẽ thông báo cho người dùng rằng hiện tại không có kết nối internet, vì vậy họ có thể kiểm tra kết nối internet của mình.
![]() |
Code hiển thị thông báo khi mất kết nối mạng cho Website/Blogspot |
Hộp thoại thông báo sẽ hiện ra ngay khi bạn bị mất kết nối mạng với máy tính của mình và sau khi khôi phục kết nối mạng một hộp thoại tiếp nữa sẽ hiện ra thông báo rằng bạn đã khôi phục kết nối mạng. Tác dụng của nó thì không nhiều nhưng mình thấy thích thì mình thêm vào tại mình thấy Facebook cũng có nên mình tò mò tìm hiểu viết ra đoạn code nhỏ giống với của Facebook. Các bạn tham khảo code bên dưới nhé!
Thêm No Internet Connection Pop-up Widget vào Trang web Blogger sẽ không yêu cầu nhiều kiến thức về HTML, CSS hoặc JS vì tôi đã thiết kế nó cho bạn. Những gì bạn cần làm là triển khai các mã ở đúng vị trí trong XML Chủ đề Blogger của bạn.
Các bước thực hiện
Quan trọng!Trước khi chúng tôi bắt đầu thêm mã trong XML, tôi khuyên bạn nên tạo một Bản sao lưu của chủ đề hiện tại của bạn. Tình cờ nếu có bất kỳ sự cố nào xảy ra, bạn có thể khôi phục lại sau.
Bước 1: Trước hết, Đăng nhập vào Trang tổng quan Blogger của bạn.
Bước 2: Trên Trang tổng quan Blogger, nhấp vào Chủ đề .
Bước 3: Nhấp vào biểu tượng mũi tên xuống bên cạnh nút 'tùy chỉnh' .
Bước 4: Nhấp vào Chỉnh sửa HTML , bạn sẽ được chuyển hướng đến trang chỉnh sửa.
Bước 5: Bây giờ, hãy tìm kiếm mã ]]></b:skin>
và dán các Mã CSS sau vào ngay trên với nó.
.icon-stt svg{display:none} #networkstt.online .icon-stt .connect-icon{display:inline-block} #networkstt.offline .icon-stt .disconnect-icon{display:inline-block} #networkstt #status-text{font-size:14px;color:#666;padding:6px} #networkstt .icon-stt{padding:6px} #networkstt{display:none;position:fixed;bottom:15px;left:15px;background:#fff;padding:4px 6px;align-items:center;border-radius:.25rem;box-shadow:0 0 20px rgb(95 125 149 / 25%);z-index:9999} #networkstt.offline,#networkstt.online{display:flex} .refresh-button{font-size:14px;display:none;color:#7577a9;margin:0 5px 0 10px;cursor:pointer} #networkstt.offline .refresh-button{display:inline-block}
Bước 6: Thêm đoạn HTML sau vào trước thẻ đóng </body>
<div id='networkstt'> <div class='icon-stt'> <svg class='connect-icon' height='24' viewBox='0 0 24 24' width='24' xmlns='http://www.w3.org/2000/svg'><path d='M0 0h24v24H0z' fill='none'></path><path d='M1 9l2 2c4.97-4.97 13.03-4.97 18 0l2-2C16.93 2.93 7.08 2.93 1 9zm8 8l3 3 3-3c-1.65-1.66-4.34-1.66-6 0zm-4-4l2 2c2.76-2.76 7.24-2.76 10 0l2-2C15.14 9.14 8.87 9.14 5 13z' fill='#2ecc71'></path></svg> <svg class='disconnect-icon' height='24' viewBox='0 0 24 24' width='24' xmlns='http://www.w3.org/2000/svg'><path d='M24 .01c0-.01 0-.01 0 0L0 0v24h24V.01zM0 0h24v24H0V0zm0 0h24v24H0V0z' fill='none'></path><path d='M22.99 9C19.15 5.16 13.8 3.76 8.84 4.78l2.52 2.52c3.47-.17 6.99 1.05 9.63 3.7l2-2zm-4 4c-1.29-1.29-2.84-2.13-4.49-2.56l3.53 3.53.96-.97zM2 3.05L5.07 6.1C3.6 6.82 2.22 7.78 1 9l1.99 2c1.24-1.24 2.67-2.16 4.2-2.77l2.24 2.24C7.81 10.89 6.27 11.73 5 13v.01L6.99 15c1.36-1.36 3.14-2.04 4.92-2.06L18.98 20l1.27-1.26L3.29 1.79 2 3.05zM9 17l3 3 3-3c-1.65-1.66-4.34-1.66-6 0z'></path></svg> </div> <p aria-atomic='true' id='status-text' role='alert'></p> <div class='refresh-button' role='button' tabindex='0'> <span onclick='location.reload()'>Refresh</span> </div> </div> <script>//<![CDATA[ window.addEventListener('load', function() { var status = document.getElementById("status-text"), classnw = document.getElementById("networkstt"); function updateOnlineStatus(event) { var networkstt = navigator.onLine ? "Your internet connection was restored." : "You are currently offline."; status.innerHTML = networkstt; if (navigator.onLine == true){classnw.className = 'online';setTimeout(function(){classnw.className = ''},3000)}else{classnw.className = 'offline'} } window.addEventListener('online', updateOnlineStatus); window.addEventListener('offline', updateOnlineStatus); }); //]]></script>
Đối với mẫu Median Ui 1.6
Bước 1: Thêm đoạn HTML sau vào trước thẻ đóng </body>
Nếu mẫu của bạn có tính năng chế độ tối và nếu bạn muốn có màu khác khi ở chế độ tối, bạn có thể tùy chỉnh các mã theo nhu cầu của mình. Mỗi mẫu có thể có một lớp chế độ tối khác nhau, vì vậy hãy điều chỉnh nó, bạn có thể thay thế lớp đã đánh dấu bằng lớp chế độ tối mẫu của mình.
/* Pop-Up Box (Style 1) by Fineshop */ .popSc{position:fixed;z-index:99980;top:0;bottom:0;left:0;right:0;padding:20px;background:#f3f5fe;display:flex;justify-content:center;align-items:center} .popSc.hidden{display:none} .popSc .popBo{position:relative;background:#fff;max-width:400px;display:flex;justify-content:center;align-items:center;flex-direction:column;padding:30px;border-radius:30px} .popSc .popBo svg{display:block;width:50px;height:50px;fill:none !important;stroke:#08102b;stroke-linecap:round;stroke-linejoin:round;stroke-width:1.5} .popSc .popBo h2{margin:10px 0 15px 0;font-size:1.2rem;font-weight:800;color:#08102b} .popSc .popBo p{margin:0;line-height:1.7em;font-size:0.9rem;color:#08102b} .popSc .popBo .popBtn{display:inline-flex;justify-content:center;align-items:center;height:50px;width:50px;outline:none;border:none;background:#f3f5fe;border-radius:50%;margin-top:20px;transition:all .2s ease;-webkit-transition:all .2s ease} .popSc .popBo .popBtn:hover{transform:scale(1.05);-webkit-transform:scale(1.05)} .popSc .popBo .popBtn svg{width:24px;height:24px;flex-shrink:0;opacity:.8} .popSc .popBo .popBtn svg.r{animation:rotateIcn 1.5s infinite linear;-webkit-animation:rotateIcn 1.5s infinite linear} .darkMode .popSc, .darkMode .popSc .popBo .popBtn{background:#1f1f1f} .darkMode .popSc .popBo{background:#2c2d31} .darkMode .popSc .popBo svg{stroke:#fefefe} .darkMode .popSc .popBo p, .darkMode .popSc .popBo h2{color:#fefefe} @keyframes rotateIcn{from{transform:rotate(0deg)} to{transform:rotate(359deg)}} @-webkit-keyframes rotateIcn{from{-webkit-transform:rotate(0deg)} to{-webkit-transform:rotate(359deg)}}
Thêm CSS sau thay vì thêm CSS được cung cấp ở trên để có giao diện thay thế với Hiệu ứng Blur.
/* Pop-Up Box (Style 2) by Fineshop */ .popSc{position:fixed;top:0;bottom:0;left:0;right:0;padding:20px;background:rgba(255, 255, 255, 0.1);z-index:99980;-webkit-backdrop-filter:blur(10px);backdrop-filter:blur(10px);display:flex;justify-content:center;align-items:center} .popSc.hidden{display:none} .popSc .popBo{position:relative;background:rgba(255, 255, 255, 0.8);-webkit-backdrop-filter:blur(10px);backdrop-filter:blur(10px);max-width:400px;display:flex;justify-content:center;align-items:center;flex-direction:column;padding:30px;border-radius:20px;box-shadow:0 5px 25px rgb(0 0 0 / 20%)} .popSc .popBo svg{display:block;width:50px;height:50px;fill:none !important;stroke:#08102b;stroke-linecap:round;stroke-linejoin:round;stroke-width:1.5} .popSc .popBo h2{margin:10px 0 15px 0;font-size:1.2rem;font-weight:800;color:#08102b} .popSc .popBo p{margin:0;line-height:1.7em;font-size:0.9rem;color:#08102b} .popSc .popBo .popBtn{display:inline-flex;justify-content:center;align-items:center;height:50px;width:50px;outline:none;border:none;background:#482dff;border-radius:50%;margin-top:20px;transition:all .2s ease;-webkit-transition:all .2s ease} .popSc .popBo .popBtn:hover{transform:scale(1.05);-webkit-transform:scale(1.05)} .popSc .popBo .popBtn svg{width:24px;height:24px;stroke:#fff;flex-shrink:0} .popSc .popBo .popBtn svg.r{animation:rotateIcn 1.5s infinite linear;-webkit-animation:rotateIcn 1.5s infinite linear} .popSc{animation:popupBlur .3s ease-in; -webkit-animation:popupBlur .3s} .popSc >*{animation:popupScale .3s ease-in; -webkit-animation:popupScale .3s} .darkMode .popSc{background:rgba(0, 0, 0, 0.1)} .darkMode .popSc .popBo{background:rgba(50, 50, 50, 0.8)} .darkMode .popSc .popBo svg{stroke:#fefefe} .darkMode .popSc .popBo p, .darkMode .popSc .popBo h2{color:#fefefe} @keyframes popupBlur {from{opacity:0}to{opacity:1}} @-webkit-keyframes popupBlur{from{opacity:0}to{opacity:1}} @keyframes popupScale{from{transform:scale(0);animation-timing-function:ease-in;opacity:0}to{transform:scale(1);opacity:1}} @-webkit-keyframes popupScale{from{-webkit-transform:scale(0);-webkit-animation-timing-function: ease-in;opacity:0}to{-webkit-transform:scale(1);opacity:1}} @keyframes rotateIcn{from{transform:rotate(0deg)} to{transform:rotate(359deg)}} @-webkit-keyframes rotateIcn{from{-webkit-transform:rotate(0deg)} to{-webkit-transform:rotate(359deg)}}
Lưu ý Chúng tôi đã sử dụng các Mã CSS ở trên trong các bài viết trước. Nếu bạn đã thêm nó trong Theme XML của mình, thì hãy bỏ qua bước này và làm theo các bước tiếp theo.
Bước 2: Thêm MãCSS sau ngay bên dưới vào Mã CSS mà chúng tôi đã thêm vào ]]></b:skin>
.
/* Toast Notification by Fineshop */ .tNtf span{position:fixed;left:24px;bottom:-70px;display:inline-flex;align-items:center;text-align:center;justify-content:center;margin-bottom:20px;z-index:99981;background:#323232;color:rgba(255,255,255,.8);font-size:14px;font-family:inherit;border-radius:3px;padding:13px 24px; box-shadow:0 5px 35px rgba(149,157,165,.3);opacity:0;transition:all .1s ease;animation:slideinwards 2s ease forwards;-webkit-animation:slideinwards 2s ease forwards} @media screen and (max-width:500px){.tNtf span{margin-bottom:20px;left:20px;right:20px;font-size:13px}} @keyframes slideinwards{0%{opacity:0}20%{opacity:1;bottom:0}50%{opacity:1;bottom:0}80%{opacity:1;bottom:0}100%{opacity:0;bottom:-70px;visibility:hidden}} @-webkit-keyframes slideinwards{0%{opacity:0}20%{opacity:1;bottom:0}50%{opacity:1;bottom:0}80%{opacity:1;bottom:0}100%{opacity:0;bottom:-70px;visibility:hidden}} .darkMode .tNtf span{box-shadow:0 10px 40px rgba(0,0,0,.2)}
Đừng thêm nếu bạn đã thêm nó trước đó..
Bước 3: Dán đoạn mã HTML sau ngay bên trên thẻ <body>
. Nếu bạn không tìm thấy nó, nó có thể đã được phân tích cú pháp<body>
.
<!--[ Toast Notification by Fineshop ]--> <div id='toastNotif' class='tNtf'></div>
Một lần nữa, không thêm nếu bạn đã thêm nó.
Bước 4: Bây giờ hãy thêm HTML just above to </body>
sau ngay bên trên thẻ <body>
. Nếu bạn không tìm thấy nó, nó có thể đã được phân tích cú pháp </body>
.
<!--[ No Internet Connection Pop-up by Fineshop ]--> <div id='noInternet' class='popSc hidden'> <div class='popBo'> <svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><line x1='1' x2='23' y1='1' y2='23'/><path d='M16.72 11.06A10.94 10.94 0 0 1 19 12.55'/><path d='M5 12.55a10.94 10.94 0 0 1 5.17-2.39'/><path d='M10.71 5.05A16 16 0 0 1 22.58 9'/><path d='M1.42 9a15.91 15.91 0 0 1 4.7-2.88'/><path d='M8.53 16.11a6 6 0 0 1 6.95 0'/><line x1='12' x2='12.01' y1='20' y2='20'/></svg> <h2>Oops! No Internet!</h2> <p>Looks like you are facing a temporary network interruption.<br/>Or check your network connection.</p> <button class='popBtn' onclick='pageReload()'><svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><polyline points='23 4 23 10 17 10'/><path d='M20.49 15a9 9 0 1 1-2.12-9.36L23 10'/></svg></button> </div> </div>
Bước 5: Sau đó, thêm JavaScript sau ngay bên dưới Mã HTML mà chúng ta đã dán ở Bước 3.
<script>/*<![CDATA[*/ /* No Internet Connection Script by Fineshop */ function pageReload(){var n=document.querySelector("#noInternet .popBo .popBtn svg");null!=n&&n.classList.add("r"),setTimeout(function(){window.location.reload()},500)};window.addEventListener("offline",function(){document.querySelector("#noInternet").classList.remove("hidden"),document.querySelector("#toastNotif").innerHTML="<span>No internet connection!</span>"}),window.addEventListener("online",function(){document.querySelector("#noInternet").classList.add("hidden"),document.querySelector("#toastNotif").innerHTML="<span>Internet connection restored!</span>"}); /*]]>*/</script>
Bước 6: Cuối cùng, Lưu các thay đổi bằng cách nhấp vào biểu tượng này
Đã xong! Bây giờ trang web của bạn sẽ hiển thị cửa sổ bật lên nói Không có kết nối Internet nếu không có kết nối internet trong thiết bị của khách truy cập.
Chỉ thêm Không có thông báo No Internet
Bây giờ, bạn sẽ làm gì nếu bạn chỉ muốn hiển thị Thông báo No Internet thay vì Cửa sổ bật lên? Đừng lo lắng, bạn cũng có thể thêm Thông báo No Internet
Đối với điều đó, hãy thay thế Mã JavaScript ở trên bằng JavaScript được cung cấp bên dưới.
<script>/*<![CDATA[*/ /* No Internet Connection Script by Fineshop (Only Toast) */ window.addEventListener("offline",function(){document.querySelector("#toastNotif").innerHTML="<span>No internet connection!</span>"}),window.addEventListener("online",function(){document.querySelector("#toastNotif").innerHTML="<span>Internet connection restored!</span>"}); /*]]>*/</script>
Bạn có thể loại bỏ các Mã CSS, HTML không cần thiết, nếu bạn đã thêm Mã JavaScript này..
Demo
Bạn muốn xem nó hoạt động?
Bạn có thể chọn Không có kiểu tiện ích con bật lên kết nối Internet trước khi áp dụng nó trên Trang web Blogger của mình.
Điều khoản sử dụng
Nếu bạn muốn sử dụng Tiện ích bật lên Không có Kết nối Internet này trên trang web của mình, vui lòng không xóa các thuộc tính khỏi mã, nó sẽ không hiển thị trên trang web của bạn.
Kết luận
Đây là tất cả về việc thêm Tiện ích bật lên Không có Kết nối Internet vào Trang web Blogger. Tôi hy vọng bạn thích bài viết này. Xin vui lòng chia sẻ bài viết này. Và nếu bạn đang gặp vấn đề trong bất kỳ phần nào hoặc bạn có bất kỳ câu hỏi nào thì hãy hỏi chúng tôi trong hộp bình luận.
© Copyright:
www.fineshopdesign.com
Truy cập Bypass Google Account APK để tải file APK nhé
Tham gia cuộc trò chuyện