DelphiFAQ Home Search:

How can I prevent the user from typing in a URL


commentsThis article has not been rated yet. After reading, feel free to leave comments and rate it.


My web pages's JavaScript needs to be notified (event) when the user types a URL in the browser's address field (planning to leave the site?). How can I do this?


It's not possible. The browsers location/address bar is not a JavaScript object, so there are no JavaScript methods for it.

However when someone comes to your site you could check for the window's name. If it is not a specific unusual name (which you hard code now), then you know that it is the first visit and the browser probably does display an address bar.
Just use javascript to open a new window (with the same url) and from there close the opening window (window.opener.

<script language=JavaScript>
var wn =,6);

if (wn!="my_secret_name_123") {, 
else {
  // close the opener

  if (document.opener) {

Content-type: text/html


2009-01-21, 08:29:35   (updated: 2009-01-21, 08:30:24) from Chile  
Excelente codigo, sirve para que no entren usuarios por url a paginas restringidas, cuando las páginas tienen frames y popus.
saludos, regards.

2017-03-23, 05:43:54
serhan from Pakistan  
I am looking for some more advanced JavaScript codes. I need to make a shopping cart with different functionalities. In the some essays are about the new programming guides and its importance. These are awesome for students.



NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: