Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9198895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:23:49+00:00 2026-06-17T22:23:49+00:00

I want a confirm message to popup when clicking on an external link. Though

  • 0

I want a confirm message to popup when clicking on an external link. Though it doesnt want to work out. I dont get the confirm popup when i click on an external link. Any solutions ?

Javascript code

function warning(){
    var warning = confirm('Do you want to leave');
    if(!warning){
    alert("Staying on site");
    return false;
    } else {
        alert("Leaving site");
    return true;
    }
}

function init() {
    var warn = document.getElementsByTagName("ul");
    for(i=0; i<warn.length; i++)
        if(warn[i].className == "meny"){
            var link = document.getElementsByTagName("li");
    }
    for(i=0; i<link.length; i++){
        var links = document.getElementsByTagName("a");
        if(links[i].className == "external"){
            links.onclick = warning;
        }
    }
}

Html code:

<ul class="meny"">
<li><a class="external" href="https://www.mah.se">Mah</a></li>
<li><a class="external" href="https://www.google.se/">Google</a></li>
<li><a class="external" href="http://www.facebook.com/">Facebook</a></li>
<li><a class="external" href="http://www.youtube.com/">Youtube</a></li>
<li><a href="#">Digitalt</a></li>
<li><a href="#">Kultur</a></li>
<li><a href="#">Nöje</a></li>
<li><a href="#">Sport</a></li>
<li><a href="#">Familj</a></li>
<li><a href="#">Resor</a></li>
<li><a href="#">Inrikes</a></li>
<li><a href="#">Utrikes</a></li>
<li><a href="#">Jobb</a></li>
</ul>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:23:50+00:00Added an answer on June 17, 2026 at 10:23 pm

    This behavior can only be accomplished by handling the onbeforeunload event. Your handler should return a string, which is the message that appears to the user. A simple example:

    window.onbeforeunload = function () {
        return 'are you sure you want to leave?';  
    };
    

    http://jsfiddle.net/rHkfM/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get a confirm message on clicking delete (this maybe a button
I have a link to delete action using Jquery dialog confirm message. Clicking on
I didn't find it on their doc http://www.sqlite.org/lang_corefunc.html So just want to get confirm
I'm trying to get the user to confirm if they want to delete a
For the following code <script type=text/javascript> $(document).ready(function(){ $(#erase).click(function(){ confirm('Are you sure you want to
After clicking popup button I want to display some text on the webpage. But
The confirm-box message appears like it should when the link is clicked. <%= link_to
I just want to confirm something I noticed when downloading a file through sftp
I just want to confirm my understanding of exceptions and how they impact their
This is an easy question and I want to confirm with you experts! I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.