So funktioniert die URL Api

URL Api , so funktioniert sie. Auslesen und setzen der Parameter

Der hier verwendete Code

<!DOCTYPE html> <html lang="en"> <head> <style> /* CSS files add styling rules to your content */ body { font-family: "Benton Sans", "Helvetica Neue", helvetica, arial, sans-serif; margin: 2em; } h1 { font-style: italic; color: #373fff; } .param-table { width: 30em; text-align: left; border: 1px solid black; } .param-table tr:nth-child(even) { background-color: #eef; } .param-table th { border-bottom: 1px solid #888; } .param-table th:nth-child(1) { width: 10em; } .param-table td { font: 14px Menlo,Courier,Monaco,monospace; } </style> <title>Hello!</title> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <script> window.addEventListener("load", event => { var r=document.referrer; fillTableWithParameters(document.querySelector(".param-table"),r); }); function fillTableWithParameters(tbl,rr) { let url = new URL(rr); url.searchParams.sort(); console.log(url); let keys = url.searchParams.keys(); for (let key of keys) { let val = url.searchParams.get(key); let row = document.createElement("tr"); let cell = document.createElement("td"); cell.innerText = key; row.appendChild(cell); cell = document.createElement("td"); cell.innerText = val; row.appendChild(cell); tbl.appendChild(row); }; } let myUsername = "someguy"; let addr = new URL(""); addr.username = myUsername; addr.strasse='sexstreet'; //console.log(addr) </script> </head> <body> <p> Testing out the URL API. Try loading this page with different parameter lists. </p> <table class="param-table"> <thead> <tr> <th>Parameter</th> <th>Value</th> </tr> </thead> </table> </body> </html>

Add Comment

* Required information
Drag & drop images (max 3)
Powered by Commentics


No comments yet. Be the first!