开发者

Trying to put alternative to noscript to work; fine but not in a mobile browser?

I recently discovered a gracefully simple way to display a message if the agent has javascript disabled, and it works great -- on my laptop..!

I tested it out on mobile safari, it's not working. Is there any reason for it not to? I took into account these things when writing my code:

  1. The markup/dom actu开发者_运维技巧ally loading/registering, so I put a script tag after the ending tag of my div
  2. Any type of reason why it shouldn't work right away, so I made use of the setTimeout function and had it wait 100 ms
  3. Used jquery just incase the good old dom lookup and style modification stuff didn't perform as well/correctly

My code:

<div id="enable-js">
        <div id="content-container">
            <div id="text_wrapper">
                <p>For the best experience, please <a href="http://www.activatejavascript.org/">enable
                    javascript</a>.
                    If your browser is not capable of using javascript,
                    please considering getting a <a href="http://alternativebrowseralliance.com/browsers.html">better
                        browser</a>.
                </p>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        (function() {
            setTimeout(function() {
                $('#enable-js').hide(); //hide area if scripts enabled
            }, 100);
        })();
    </script>

Thanks in advance, guys.

EDIT:

I confirmed the problem is not with Webkit; as well as the fact that it makes no difference starting it off with a self-invoking anonymous function or by placing the hiding code in window.onload as opposed to after the div's closing tag.

EDIT2:

Confirmed that doing document.getElementById and setting display to none isn't working either! What is going on...


Try using the load() event and if that doesn't work $(document).ready() is almost absolutely sure to do what you want.

You should try using a webkit browser on your computer and see if it isn't a webkit problem.


Edit: whole new idea.

It could be that mobile safari doesn't support desktop jquery.

You could either try jQuery mobile. Or this:

    (function() {
        setTimeout(function() {
            $('#enable-js').css({'display':'none'}); //hide area if scripts enabled
        }, 100);
    })();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜