没有不值得去解决的问题,也没有不值得去学习的技术!

Analysis and Fix for Missing Baidu and Alimama Ads Under HTTPS

After upgrading the website to HTTPS, the Baidu and Alimama ad embeds were not displaying

1. After upgrading the website to HTTPS, the Baidu and Alimama ad embeds were not displaying, as shown in Figure 1.

After upgrading the website to HTTPS, the Baidu and Alimama ad embeds were not displaying
Figure 1

2. The Baidu ad embed code contains HTTP URLs.

JavaScript



(function() {
    var s = "_" + Math.random().toString(36).slice(2);
    document.write('<div id="' + s + '"></div>');
    (window.slotbydup=window.slotbydup || []).push({
        id: '6758467',
        container: s,
        size: '200,280',
        display: 'inlay-fix'
    });
})();





</pre>

3. The Alimama ad embed code contains HTTP URLs.

JavaScript


        document.write('<a style="display:none!important" id="tanx-a-mm_123311466_23836172_109841700208"></a>');
        tanx_s = document.createElement("script");
        tanx_s.type = "text/javascript";
        tanx_s.charset = "gbk";
        tanx_s.id = "tanx-s-mm_123311466_23836172_109841700208";
        tanx_s.async = true;
        tanx_s.src = "http://p.tanx.com/ex?i=mm_123311466_23836172_109841700208";
        tanx_h = document.getElementsByTagName("head")[0];
        if(tanx_h)tanx_h.insertBefore(tanx_s,tanx_h.firstChild);


4. Based on the browser prompt: after clicking “Load unsafe scripts”, the Baidu ad displayed, but the Alimama ad still did not display, and the browser indicated the page was unsafe, as shown in Figure 2.

Based on the browser prompt: after clicking "Load unsafe scripts", the Baidu ad displayed, but the Alimama ad still did not display, and the browser indicated the page was unsafe
Figure 2

5. Fortunately, both Baidu and Alimama already support the HTTPS protocol. After adjusting the ad embed code by replacing http:// with https://, I reopened the webpage; both ads displayed successfully, and there were no more security warnings, as shown in Figure 3.

Fortunately, both Baidu and Alimama already support the HTTPS protocol. After adjusting the ad embed code by replacing http:// with https://, I reopened the webpage; both ads displayed successfully, and there were no more security warnings
Figure 3
JavaScript




<script type="text/javascript">
        document.write('<a style="display:none!important" id="tanx-a-mm_123311466_23836172_109841700208"></a>');
        tanx_s = document.createElement("script");
        tanx_s.type = "text/javascript";
        tanx_s.charset = "gbk";
        tanx_s.id = "tanx-s-mm_123311466_23836172_109841700208";
        tanx_s.async = true;
        tanx_s.src = "https://p.tanx.com/ex?i=mm_123311466_23836172_109841700208";
        tanx_h = document.getElementsByTagName("head")[0];
        if(tanx_h)tanx_h.insertBefore(tanx_s,tanx_h.firstChild);


关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系