Check if a URL contains a given string using JavaScript

The demo here shows how to check whether the URL (or the address bar) of this page contains a given string using JavaScript. I have used indexOf() method.

Click the button to check if the URL of this page contains the string ?book=

Go back to the Tutorial
More interesting and interactive Demos