菜鸟教程小白 发表于 2022-12-12 13:07:34

Javascript window.onload 在 iOS 强制门户/网络中不起作用


                                            <p><p>我在一个 jsp 文件的头部有这段代码。出于某种原因,它在桌面和移动浏览器上运行良好,但在 iOS 强制门户上,只触发了第一个警报。有谁知道为什么?</p>

<p></p><div class="snippet"data-lang="js"data-hide="false"data-console="true"data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>&lt;script type=&#34;text/javascript&#34;&gt;
alert(&#34;first alert&#34;);
window.onload = function() {
    alert(&#34;second alert&#34;);
};
&lt;/script&gt;</code></pre>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我想通了。使用这个作品...... </p>

<p></p><div class="snippet"data-lang="js"data-hide="false"data-console="true"data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>&lt;script type=&#34;text/javascript&#34;&gt;
alert(&#34;first alert&#34;);
window.addEventListener(&#39;load&#39;,
    function() {
      alert(&#34;second alert&#34;);
    }, false);
&lt;/script&gt;</code></pre>

                                                <p style="font-size: 20px;">关于Javascript window.onload 在 iOS 强制门户/网络中不起作用,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/42568320/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/42568320/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: Javascript window.onload 在 iOS 强制门户/网络中不起作用