OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <body> | 3 <body> |
4 </body> | 4 </body> |
5 <script> | 5 <script> |
6 function getQueryStrings() { | 6 function getQueryStrings() { |
7 // Gets query parameters from the URL; e.g., given a URL like: | 7 // Gets query parameters from the URL; e.g., given a URL like: |
8 // | 8 // |
9 // http://<url>/my.html?test=123&bob=456 | 9 // http://<url>/my.html?test=123&bob=456 |
10 // | 10 // |
11 // returns params["test"] = 123, params["bob"]=456, etc. | 11 // returns params["test"] = 123, params["bob"]=456, etc. |
12 var params = {}; | 12 var params = {}; |
13 | 13 |
14 // RegEx to split out values by &. | 14 // RegEx to split out values by &. |
15 var r = /([^&=]+)=?([^&]*)/g; | 15 var r = /([^&=]+)=?([^&]*)/g; |
16 | 16 |
17 // Lambda function for decoding extracted match values. Replaces '+' with | 17 // Lambda function for decoding extracted match values. Replaces '+' with |
18 // space so decodeURIComponent functions properly. | 18 // space so decodeURIComponent functions properly. |
19 function d(s) { return decodeURIComponent(s.replace(/\+/g, ' ')); } | 19 function d(s) { return decodeURIComponent(s.replace(/\+/g, ' ')); } |
20 | 20 |
21 var match; | 21 var match; |
22 while (match = r.exec(window.location.search.substring(1))) | 22 while (match = r.exec(window.location.search.substring(1))) |
23 params[d(match[1])] = d(match[2]); | 23 params[d(match[1])] = d(match[2]); |
24 | 24 |
25 return params; | 25 return params; |
26 } | 26 } |
27 qsParams = getQueryStrings(); | 27 qsParams = getQueryStrings(); |
28 if (qsParams["type"] != "") { | 28 if (qsParams["type"]) { |
29 testElement = document.createElement(qsParams["type"]); | 29 testElement = document.createElement(qsParams["type"]); |
30 if (qsParams["id"] != "") | 30 if (qsParams["id"]) |
31 testElement.id = qsParams["id"]; | 31 testElement.id = qsParams["id"]; |
32 testElement.src = qsParams["src"]; | 32 testElement.src = qsParams["src"]; |
33 testElement.controls = true; | 33 testElement.controls = true; |
34 document.body.appendChild(testElement); | 34 document.body.appendChild(testElement); |
35 } | 35 } |
36 </script> | 36 </script> |
37 </html> | 37 </html> |
OLD | NEW |