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 abc.com to xyz.com and alert box showing xyz.com + msg ?
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
alertentirely, 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 whilealert(andconfirmandprompt) 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 thisalertcode:becomes
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:
HTML:
CSS:
JavaScript:
Live example
Obviously you’d want to tart that up a bit, and again, this is a bare-bones example, not a complete solution.