TypechoJoeTheme

Dcr163的博客

统计

微信设置字体大写导致页面排版错乱,页面设置禁止生效的代码

2024-04-11
/
2 评论
/
3,569 阅读
/
正在检测是否收录...
04/11

IOS在css上新增

body {
            /* IOS禁止微信调整字体大小 */
            -webkit-text-size-adjust: 100% !important;
            text-size-adjust: 100% !important;
            -moz-text-size-adjust: 100% !important;
        }

Android

在 Android 下,需要通过 WeixinJSBridge 对象将网页的字体大小设置为默认大小,并且重写设置字体大小的方法,让用户不能在该网页下设置字体大小。

    <!-- 强制禁止用户修改微信客户端的字体大小 -->
    (function() {
        if (typeof WeixinJSBridge == "object" && typeof WeixinJSBridge.invoke == "function") {
            handleFontSize();
        } else {
            if (document.addEventListener) {
                document.addEventListener("WeixinJSBridgeReady", handleFontSize, false);
            } else if (document.attachEvent) {
                document.attachEvent("WeixinJSBridgeReady", handleFontSize);
                document.attachEvent("onWeixinJSBridgeReady", handleFontSize);  }
        }
        function handleFontSize() {
            // 设置网页字体为默认大小
            WeixinJSBridge.invoke('setFontSizeCallback', { 'fontSize' : 0 });
            // 重写设置网页字体大小的事件
            WeixinJSBridge.on('menu:setfont', function() {
                WeixinJSBridge.invoke('setFontSizeCallback', { 'fontSize' : 0 });
            });
        }
    })();
    <!-- 强制禁止用户修改微信客户端的字体大小 end -->

朗读
赞(0)
版权属于:

Dcr163的博客

本文链接:

http://dcr163.cn/714.html(转载时请注明本文出处及文章链接)

评论 (2)
  1. Kerrie Bostick 作者
    Linux · Google Chrome

    I think that what you wrote was very reasonable.
    But, consider this, what if you added a little information? I am not suggesting your content isn't solid, but suppose you added a post title that grabbed folk's attention? I mean Dcr163的博客 is kinda vanilla. You ought to peek at Yahoo's home page and note how they create post titles to get viewers to open the links.
    You might add a video or a pic or two to get people interested about everything've got to say. Just my opinion, it would make your posts a little bit more interesting.

    2024-12-28 回复
    1. Shadow 作者
      Windows 10 · Google Chrome
      @Kerrie Bostick

      Thank you for your advice.

      2024-12-28 回复

人生倒计时

今日已经过去小时
这周已经过去
本月已经过去
今年已经过去个月

最新回复

  1. slot demo
    2025-01-13
  2. 陌天
    2025-01-09
  3. Kerrie Bostick
    2024-12-28
  4. Norma Gainey
    2024-09-21
  5. Amber Powlett
    2024-05-09

标签云