{"id":63,"date":"2009-11-13T22:49:45","date_gmt":"2009-11-13T14:49:45","guid":{"rendered":"http:\/\/tmp.xujiwei.com\/blog\/?p=63"},"modified":"2010-01-28T22:06:55","modified_gmt":"2010-01-28T14:06:55","slug":"avoid-pass-parameters-through-src","status":"publish","type":"post","link":"https:\/\/xujiwei.com\/blog\/2009\/11\/avoid-pass-parameters-through-src\/","title":{"rendered":"\u614e\u7528 script \u8282\u70b9\u7684 src \u5c5e\u6027\u6765\u4f20\u9012\u53c2\u6570"},"content":{"rendered":"<p>\u5728\u6709\u4e9b\u4f7f\u7528\u00a0javascript\u00a0\u6765\u6e32\u67d3\u6570\u636e\u7684\u65f6\u5019\uff0c\u4e3a\u4e86\u80fd\u52a8\u6001\u83b7\u53d6\u4e0d\u540c\u7684\u6570\u636e\uff0c\u5e76\u4e14\u4fdd\u6301\u00a0javascript\u00a0\u4ee3\u7801\u7684\u53ef\u6269\u5c55\u6027\uff0c\u4f1a\u5c06\u00a0javascript\u00a0\u4ee3\u7801\u4e2d\u83b7\u53d6\u6570\u636e\u7684\u90e8\u5206\u9700\u8981\u7684\u53c2\u6570\u63d0\u53d6\u51fa\u6765\uff0c\u505a\u4e3a\u53c2\u6570\u653e\u5728\u00a0script\u00a0\u8282\u70b9\u7684\u5916\u90e8\u3002<\/p>\n<p>\u4e00\u822c\u6765\u8bf4\uff0c\u4f20\u9012\u53c2\u6570\u5230\u00a0javascript\u00a0\u6587\u4ef6\u5185\u90e8\u7684\u65b9\u6cd5\u6709\u4e24\u79cd\uff0c\u4e00\u79cd\u662f\u5c06\u53c2\u6570\u5199\u5728\u4e00\u4e2a\u00a0script\u00a0\u8282\u70b9\u4e2d\uff0c\u5199\u6210\u5168\u5c40\u53d8\u91cf\u7684\u65b9\u5f0f\u7684\u4f20\u9012\u7ed9\u7d27\u63a5\u7740\u8fd9\u4e2a\u00a0script\u00a0\u8282\u70b9\u7684\u5916\u90e8\u00a0javascript\u00a0\u4e2d\uff0cGoogle\u00a0Analytics\u00a0\u5c31\u662f\u4f7f\u7528\u8fd9\u6837\u7684\u65b9\u5f0f\uff1a<\/p>\n<pre lang=\"html4strict\" escaped=\"true\">&lt;script\u00a0type=\"text\/javascript\"&gt;\r\nvar\u00a0p1\u00a0=\u00a0\"v1\",\u00a0p2\u00a0=\u00a0\"v2\";\r\n&lt;\/script&gt;\r\n&lt;script\u00a0type=\"text\/javascript\"\u00a0src=\"foo.js\"&gt;&lt;\/script&gt;<\/pre>\n<p>\u53e6\u5916\u4e00\u79cd\u662f\u5c06\u53c2\u6570\u76f4\u63a5\u5199\u5728 script \u8282\u70b9\u7684 src \u5c5e\u6027\u4e2d\uff0c\u76f8\u5f53\u4e8e\u4e00\u4e2a\u9875\u9762\u7684\u67e5\u8be2\u5b57\u7b26\u4e32\u4e00\u6837\uff1a<\/p>\n<pre lang=\"html4strict\" escaped=\"true\">&lt;script\u00a0type=\"text\/javascript\"\u00a0src=\"foo.js?p1=v1&amp;p2=v2\"&gt;&lt;\/script&gt;<\/pre>\n<p>\u4e0d\u8fc7\uff0c\u4f7f\u7528\u00a0script\u00a0\u8282\u70b9\u7684\u00a0src\u00a0\u5c5e\u6027\u6765\u4f20\u9012\u53c2\u6570\u9700\u8981\u6ce8\u610f\u4e00\u4e2a\u5f88\u91cd\u8981\u7684\u95ee\u9898\uff0c\u90a3\u5c31\u662f<strong>\u52a8\u6001\u53d8\u5316\u7684\u00a0src\u00a0\u5c5e\u6027\u4f1a\u5bfc\u81f4\u7f13\u5b58\u5931\u6548<\/strong>\u3002<\/p>\n<p>\u73b0\u5728\uff0c\u4e3a\u4e86\u7f51\u7ad9\u6027\u80fd\u7684\u9700\u8981\uff0c\u4e00\u822c\u90fd\u4f1a\u5c06\u00a0javascript\u00a0\u6587\u4ef6\u653e\u5728\u72ec\u7acb\u7684\u670d\u52a1\u5668\u4e0a\uff0c\u5e76\u8bbe\u7f6e\u4e00\u4e2a\u8f83\u957f\u7684\u8fc7\u671f\u65f6\u95f4\uff0c\u8fd9\u6837\u5ba2\u6237\u7aef\u53ea\u4f1a\u5728\u7b2c\u4e00\u6b21\u8bbf\u95ee\u7f51\u7ad9\u65f6\u9700\u8981\u53bb\u4e0b\u8f7d\u8fd9\u4e2a\u00a0javascript\u00a0\u6587\u4ef6\u3002\u4f46\u662f\uff0c\u5982\u679c\u4f7f\u7528\u00a0src\u00a0\u6765\u4f20\u9012\u53c2\u6570\uff0c\u5c31\u53ef\u80fd\u4f1a\u4f7f\u8fd9\u79cd\u7f13\u5b58\u7b56\u7565\u5931\u6548\u3002\u7279\u522b\u662f\u00a0src\u00a0\u4e2d\u5b58\u5728\u52a8\u6001\u53c2\u6570\u7684\u60c5\u51b5\uff0c\u4f8b\u5982\u7edf\u8ba1\u811a\u672c\u4e2d\u5982\u679c\u6709\u4e00\u4e2a\u00a0ip\u00a0\u53c2\u6570\uff0c\u90a3\u4e48\u8bbf\u5ba2\u6bcf\u6b21\u8fde\u4e0a\u7ebf\u65f6\uff0c\u53ef\u80fd\u00a0ip\u00a0\u90fd\u4f1a\u4e0d\u540c\uff0c\u5c31\u4f1a\u5bfc\u81f4\u00a0javascript\u00a0\u7f13\u5b58\u5931\u6548\u4e86\u3002<\/p>\n<p>\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u7684\u65b9\u6cd5\u4e5f\u5f88\u7b80\u5355\uff0c\u7b80\u5355\u5730\u7684\u5c06\u00a0src\u00a0\u5c5e\u6027\u4e2d\u7684\u53c2\u6570\u653e\u5230\u00a0script\u00a0\u8282\u70b9\u7684\u4e00\u4e2a\u81ea\u5b9a\u4e49\u5c5e\u6027\u4e2d\u5c31\u53ef\u4ee5\u4e86\uff0c\u4f8b\u5982\u00a0data-args\uff0c\u800c\u00a0src\u00a0\u5c5e\u6027\u53ea\u9700\u8981\u4fdd\u7559\u4e00\u4e2a\u65f6\u95f4\u6233\u5c31\u53ef\u4ee5\u4e86\u3002\u56e0\u4e3a\u4f7f\u7528\u00a0src\u00a0\u5c5e\u6027\u6765\u4f20\u9012\u53c2\u6570\u672c\u6765\u5c31\u9700\u8981\u5b9a\u4f4d\u00a0script\u00a0\u8282\u70b9\uff0c\u6240\u4ee5\u6539\u7531\u00a0data-args\u00a0\u81ea\u5b9a\u4e49\u5c5e\u6027\u6765\u4f20\u9012\u53c2\u6570\u5e76\u4e0d\u4f1a\u589e\u52a0\u989d\u5916\u7684\u4ee3\u7801\u3002\u53ea\u4e0d\u8fc7\u9875\u9762\u4f1a\u901a\u4e0d\u8fc7\u00a0w3c\u00a0\u7684\u9a8c\u8bc1\u7f62\u4e86\u00a0:)<\/p>\n<pre lang=\"html4strict\">&lt;script\u00a0type=\"text\/javascript\"\u00a0src=\"foo.js\"\u00a0data-args=\"p1=v1&amp;p2=v2\"&gt;&lt;\/script&gt;<\/pre>\n<p>\u518d\u6b21\u63d0\u9192\uff0c<strong>\u614e\u7528<\/strong> script\u00a0\u8282\u70b9\u7684\u00a0src\u00a0\u5c5e\u6027\u6765\u4f20\u9012\u53c2\u6570\u00a0:)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u6709\u4e9b\u4f7f\u7528\u00a0javascript\u00a0\u6765\u6e32\u67d3\u6570\u636e\u7684\u65f6\u5019\uff0c\u4e3a\u4e86\u80fd\u52a8\u6001\u83b7\u53d6\u4e0d\u540c\u7684\u6570\u636e\uff0c\u5e76 &hellip;<\/p>\n<p class=\"read-more\"><a href=\"https:\/\/xujiwei.com\/blog\/2009\/11\/avoid-pass-parameters-through-src\/\">\u7ee7\u7eed\u9605\u8bfb &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[11],"tags":[28,25],"_links":{"self":[{"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/posts\/63"}],"collection":[{"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/comments?post=63"}],"version-history":[{"count":0,"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/posts\/63\/revisions"}],"wp:attachment":[{"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/media?parent=63"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/categories?post=63"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/tags?post=63"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}