More JavaScript interacting with the DOM

This web page contains some JavaScript code that interacts with the DOM. Look at the source code of this page to see the JavaScript code.

Rewriting an HTML page in the browser using JavaScript

The button below uses the function document.write to rewrite the entire content of the current web page loaded in your browser.

A nicer demo of rewriting an HTML page in the browser using JavaScript

A bit nicer is the button below, which only rewrites part of the content of your webpage, namely the paragraph with the tag "demo" just above

A small paragraph of text, with the tag demo.

Inspecting the URL with JavaScript

Below we use javascript to extract the URL from the DOM. You can test that this works by adding superfluous parameters to the URL, e.g. ?naam=piet, or adding a fragment at the end of the URL, e.g. #demo. For example, click here.

Check that the URL in the text above matches the URL in the address bar of your browser.

Extracting parameters from the URL

We can extract parameters from the URL. See the paragraph below. Try changing the value of the 'naam' parameter in the address bar, and reload the page, to see this in action.

Change the 'naam' in the URL to a numeric value, reload the page, and then click the button below.