SKU SKU - 2 months ago 5
Javascript Question

Javascript alert showing site url. How can i remove site url from top of javascript alert?

javascript alert box showing url + msg. i have not passed any thing but it shows url on the top of alert box. how can i remove this url ? The url is showing when my site is redirected from another site.

Means redirect from to and alert box showing + msg ?


How can i remove site url from top of javascript alert?

You can't. The browser adds that so that the user knows that the message isn't from the browser itself.

The only thing you can do is stop using alert entirely, and instead use modern techniques for overlaying an element on top of the page. You can write this yourself, or use any of the many "lightbox" libraries out there. Note that doing so changes how you code things a bit, because while alert (and confirm and prompt) bring execution of scripts on the page to a screeching halt while they're on-screen, you can't do that in your own code, so you have to structure your code to continue when it receives the event that the user dismissed the box. Usually the library will give you a callback you can use for that, so for instance this alert code:

function foo() {
    if (x != 42) {


function foo() {
    someNiftyLightboxThingy("Foo!", function() {
        if (x != 42) {

Not hard, you just have to get used to it.

You don't have to use a library for this, but doing so lets you not worry about edge cases and may offer you more features. Here's a fairly bare-bones example:


<input type='button' id='btnPopup' value='Click for Pop-Up'>


iframe.shim {
  width:            100%;
  height:           100%;
  position:         absolute;
  left:             0px;
  top:              0px;
  z-index:          100;
  background-color: #fff;
  opacity:          0.5;                 /* Standard */
  filter:           alpha(opacity = 50); /* For IE */
div.overlay {
  z-index:          101;
  border:           1px solid black;
  background-color: #ecc;
  position:         absolute;
  left:             100px;
  top:              100px;


function doVerySimplePopup(text, callback) {
  var shim, div, parent = document.body;

  shim = document.createElement('iframe');
  shim.className = 'shim';

  div = document.createElement('div');
  div.className = 'overlay';
  div.innerHTML = text;
  div.onclick = function() {
    if (typeof callback === "function") {
      try { callback(); } catch (e) { }

Live example

Obviously you'd want to tart that up a bit, and again, this is a bare-bones example, not a complete solution.