Beispiel:JS-Funktionen-encodeURI.html

Aus SELFHTML-Wiki
Wechseln zu: Navigation, Suche
<!DOCTYPE html>
<html lang="de">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="./Beispiel:SELFHTML-Beispiel-Grundlayout.css">

<script>
'use strict';
document.addEventListener('DOMContentLoaded', function () {
 
  document.querySelector('#interaktiv').addEventListener('click', encode);
    
  function encode () { 
    var url = document.querySelector('a').href;
    document.querySelector('output').innerText = encodeURI(url);
  }

});

	
</script>
<style>
output {
	font-weight: bold;
}
</style>
  <title>URL mit encodeURI kodieren</title>
</head>
<body>
  <h1>URL mit encodeURI kodieren</h1>
 
<main>
    <a href="https://www.example.org/cgi-bin/script.pl?Text=der übergebene Text&Name=Stefan Münz">https://www.example.org/cgi-bin/script.pl?Text=der übergebene Text&Name=Stefan Münz</a>
    <p>kodierte URL: <code><output></output></code></p>
<button id="interaktiv">URL kodieren!</button>

</main>
</body>
</html>