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 265177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:44:50+00:00 2026-05-11T22:44:50+00:00

Below is the code from a plugin for Joomla. It works on it’s own

  • 0

Below is the code from a plugin for Joomla. It works on it’s own and it’s purpose is to detect external links on the page and force them into new browser windows using _blank.

I’ve tried for about an hour (I don’t know javascript well) but I can’t seem to figure out how to get an onclick function working.

End result, I want to add to this script the ability of a confirmation dialog, shown in the 2nd code section.

An external link, when clicked, will pop up the confirmation dialog, and if it says yes, they will be able to get to the external URL, opening in a new window. Otherwise, it cancels, and does nothing.

When I create a link with

onclick="return ExitNotice(this.href);"

within it it works perfectly, but since my website has multiple people submitting input, I’d like the confirmation box global.

this.blankwin = function(){
  var hostname = window.location.hostname;
  hostname = hostname.replace("www.","").toLowerCase();
  var a = document.getElementsByTagName("a");   
  this.check = function(obj){
    var href = obj.href.toLowerCase();
    return (href.indexOf("http://")!=-1 && href.indexOf(hostname)==-1) ? true : false;              
  };
  this.set = function(obj){
    obj.target = "_blank";
    obj.className = "blank";
  };    
  for (var i=0;i<a.length;i++){
    if(check(a[i])) set(a[i]);
  };        
};

this.addEvent = function(obj,type,fn){
  if(obj.attachEvent){
    obj['e'+type+fn] = fn;
    obj[type+fn] = function(){obj['e'+type+fn](window.event );}
    obj.attachEvent('on'+type, obj[type+fn]);
  } else {
    obj.addEventListener(type,fn,false);
  };
};
addEvent(window,"load",blankwin);

Second Part

/* ----------
  OnClick External Link Notice
---------- */
function ExitNotice(link,site,ltext) {
  if(confirm("-----------------------------------------------------------------------\n\n" + 
    "You're leaving the HelpingTeens.org website. HelpingTeens.org\ndoes not " + 
    "control this site and its privacy policies may differ\nfrom our own. " + 
    "Thank you for using our site.\n\nYou will now access the following link:\n"  + 
    "\n" + link + "\n\nPress \'OK\' to proceed, or  press \'Cancel\' to remain here." + 
    "\n\n-----------------------------------------------------------------------")) 
  {
  return true;
} 
history.go(0);
return false;
}

A) Can anyone help me fix this problem?
or B) Is there a better solution?

  • 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-05-11T22:44:50+00:00Added an answer on May 11, 2026 at 10:44 pm

    So, I’ll summarize my what I think you’re asking and then tell you how I think that can be solved. It’s possible I’ve misunderstood your question.

    You’ve got code that goes through all tags and sets their target attribute to “_blank” and sets their className to “blank”, and you’d like to instead rewrite the links to use JavaScript to show a confirmation dialog and only go to the location if the user clicks Yes.

    In this case I believe you want the links to end up as though they were written like so:

    <a href="javascript:void(0)" onclick="if (ExitNotice('http://www.whatever.com')) window.location.assign('http://www.whatever.com')">
    

    The javascript:void(0) causes the normal browser handling of the click to not go to another page, so that your onclick has time to execute.

    To make this happen, you’ll want to change the definition of this.set (inside this.blankwin) to something like this:

      this.set = function(obj){
        var href = obj.href;
        obj.href = "javascript:void(0)";
        obj.onclick = function() { (if ExitNotice(href) window.location.assign(href); };
        obj.target = "_blank";
        obj.className = "blank";
      };
    

    See here for info on void(0).

    Also, note that the code that sets obj.className to “blank” isn’t great, because it will remove any other className already assigned to the link. You could instead just add the class name to the existing ones, like so:

    obj.className = obj.className + " blank";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 186k
  • Answers 187k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Here's a KB article that can help you get started:… May 12, 2026 at 5:18 pm
  • Editorial Team
    Editorial Team added an answer By "vertical" table, do you mean the EAV model? If… May 12, 2026 at 5:18 pm
  • Editorial Team
    Editorial Team added an answer I guess I'll answer my own question. The main problem… May 12, 2026 at 5:18 pm

Related Questions

Below is the code from a plugin for Joomla. It works on it's own
I am working on a website using a PHP script to display information formatted
I am using a jQuery plugin to set cookies and when I use localhost
I'm trying to make a quick jquery plugin (as a learning exercise) for making
Thank you all ahead of time. This is my first time developing a jQuery

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.