Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Apr 2016
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need Alert Popup while clicking Important Link's

    Hi Team,

    I'm working on a simple HTML project in my office. Now my requirement is whenever I'm clicking a important links then i need a pop up stating that "Be Careful" or some other alert message.
    Kindly help me how to give this.

    Note:

    In one file i have multiple links, but when ever i click one particular link i need an alert not for the others.

    Thanks in advance.

  2. #2
    Regular Coder Synaptic's Avatar
    Join Date
    Apr 2015
    Location
    Las Vegas
    Posts
    127
    Thanks
    2
    Thanked 12 Times in 12 Posts
    This should probably be done using Javascript and should therefore be moved to the appropriate section. You can probably google this and find some different solutions.

    However, I'm bored so here's a basic example:

    /* Note! I'm not strong with Javascript so this might not be the most efficient way to accomplish your task but it does work in modern browsers. */

    Javascript:
    Code:
    var elems = document.getElementsByClassName('confirmation');
        var confirmLink = function (e) {
            if (!confirm('Please be careful visiting external links. Are you sure you want to continue?')) e.preventDefault();
        };
        for (var i = 0, l = elems.length; i < l; i++) {
            elems[i].addEventListener('click', confirmLink, false);
        }
    HTML:

    Code:
    <a target="_blank" href="Google" class="confirmation">click me</a>


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •