javascript - Disadvantage of having inline JS -
i wondering paragraph meant?
it taken website disadvantages inline scripts
poor accessibility : when comes inline javascript code, such in above example, it’s applied element doesn’t have built-in fallback interaction handler
link: https://robertnyman.com/2008/11/20/why-inline-css-and-javascript-code-is-such-a-bad-thing/
<div style="width: 800px; margin: 1em auto; font: bold 1em/1.2 verdana, arial, helvetica, sans-serif"> <div style="float: left; width: 400px; padding: 1em 2em; font-size: 0.9em"> <span id="get-shit" onclick="callsomefunction()">news</span> </div> </div>
he saying in above function if callsomefunction, redirects page other page... reason(due network error can't load) callsomefunction isn't loaded in page, dead link nothing, rather should implemented in such way without javascript should work reasonably...
even browser provides configuration disable javascript user, in case above link nothing
so saying using below code that,
<link rel="stylesheet" href="css/base.css" type="text/css" media="screen"> <script type="text/javascript" src="js/base.js"></script> <div id="container"> <div id="navigation"> <a id="get-news" href="news-proper-url">news</a> </div> </div> /* css code, in separate file (base.css) */ #container { width: 800px; margin: 1em auto: font: bold 1em/1.2 verdana, arial, helvetica, sans-serif; } #navigation { float: left; width: 400px; padding: 1em 2em; font-size: 0.9em; } /* javascript code, in separate file (base.js) */ window.onload = function () { document.getelementbyid("get-news").onclick = function () { // news through ajax }; }
here, if javascript not loaded clicking on "news" redirect new page,
if javascript loaded send ajax request , load news in same page
which cases on unavailability of javascript listed in same page
doesn’t have javascript nowadays?
first: no don’t. second: people purposely turn off (for instance, noscript firefox extension has had 31 million downloads date). third, not end user, external circumstances don’t control, will, extent or another, lead javascript being unavailable. these factors are:
antivirus programs , firewalls being bit harsh in javascript security judgement. company proxy servers filtering out code (for example, read important lesson learned ajax , accessibility). other company internet access settings preventing proper javascript execution.
Comments
Post a Comment