最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Prevent to load a page with js disabled - Stack Overflow

programmeradmin1浏览0评论

It's possible to disable an entire page html if the js is disabled on the browser of the user?
EDIT:
Thank you all for the answers and ments! However, what I mean is: I want that the page is replaced with something else, like an image, in that case.

It's possible to disable an entire page html if the js is disabled on the browser of the user?
EDIT:
Thank you all for the answers and ments! However, what I mean is: I want that the page is replaced with something else, like an image, in that case.

Share Improve this question edited May 23, 2016 at 18:57 CCT asked May 23, 2016 at 18:45 CCTCCT 611 silver badge8 bronze badges 5
  • not exactly a duplicate, but this thread will answer your question: stackoverflow./questions/6724515/… – durbnpoisn Commented May 23, 2016 at 18:49
  • Do you mean disable a link to page? Or what do you mean exactly by "disable"? – Steven B. Commented May 23, 2016 at 18:50
  • You'll probably need the page to render the replaced content by default with a JS call that actually swaps that out for the real content. If JS is disabled, the call won't go through and the failover content is shown, but if the JS call is successful then it would show the proper content – theaccordance Commented May 23, 2016 at 19:00
  • I edited the question. Sorry if I wasn't clear enough. – CCT Commented May 23, 2016 at 19:00
  • @Yosvel's answer is what you want. – Seth Commented May 23, 2016 at 19:17
Add a ment  | 

2 Answers 2

Reset to default 7

The noscript tag defines an alternate content for users that have disabled scripts in their browser or have a browser that doesn't support script.

You can do something like this in your html body to display whatever image you want to show:

<noscript>
    <style type="text/css">
        .wrapper {display:none;}
    </style>
    <div>
        <img src="src/to/your/image.png" alt="You don't have javascript enabled">
    </div>
</noscript>

The css inside the noscript tag will hide the html content inside the wrapper class.

Not that I am aware of. Somewhere somehow you need to tell the browser to prevent the action/event linked to it, eg returning false, which is a task for javascript. I can e up with two alternatives:

Make all anchors dummies and correct them when JS is turned on:

<a href="#" data-href="/actual-url">foo</a> 
$('a').each(function(){ this.href = $(this).data("href");} // * jQuery for simplicity

Put an layer on top of the anchor, which you can remove with JS.

.BlockedAnchor a{ position: relative; }
.BlockedAnchor a:before{ 
    position: absolute; 
    display: block;
    top: 0; 
    left: 0;
    width: 100%;
    height: 100%;
}
$('body'removeClass("BlockedAnchor");
发布评论

评论列表(0)

  1. 暂无评论