joomla - Javascript problem with a global external link confirmation alert -


Below is a plugin code for Joomla, it works on its own, and its purpose is to find external links on the page and They have to force them in a new browser window using _blank.

I have tried for about an hour (I do not know Javascript properly) but I can not seem to know how to work on an onclick function.

The end result, I want to add the ability of a confirmation dialog in this script, which is shown in the second code section.

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

When I will create a link with preclick = "return ExitNotice (this.href)", " inside it works perfectly, but since in my website Many people are collecting input, I want 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 & amp; href.indexOf (hostname) == - 1) right? Wrong;} this.set = function (obj) {obj.target =" _blank "; Obj.className = "Empty";}; (Var i = 0; i & lt; a.length; i + (If (check (a [ii])) set (a [ii]);};}; 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 (' over '+ type, obj [Type + fn]);} and {obj.addEventListener (type, Fn, false); }; }; AddEvent (window, "load", blankwin);  

Part II

  / * ---------- OnClick External Link Notices ---------- * / Function ExitNotice (link, site, ltext) {If (Confirm ("--------------------------------- - ------------------------------------- \ n \ n "+" You are leaving HelplingTance The .org website.HelpingingTeens.org \ "does not control this site and its privacy policies may differ from our own." + "Thank you for using our site. \ N \ nYou can now Link will access: \ n "+" \ N "+ link +" \ n \ nTo proceed Press \ "OK \ ', or press \" Cancel \ "to stay here." + "\ N \ n ---------- ------------- ------------------------------------- ----------- ") } {Return true;} History.go (0); the description is false;}  

a) Can someone help me fix this problem? Or b) Is there a better solution?

Then, again asking and then tell me how I feel It can be solved. It is possible that I misunderstood your question.

The code that you have received goes through all the tags and sets its target attribute for "_blank" and sets its classname to "blank", and you instead have a confirmation To use the JavaScript to show the dialog, rewrite the link and if the user clicks the click, just go to that place.

In this case, I believe that you want to end the link as if it was written:

   

To do this, you will want to change the definition of this. Set (inside this. Blankwin) Something like this:

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

Look for information on zero (0).

Also, note that the code that sets "blank" obj.className is not very good, because it is already assigned Any other classname removed will link the link. You can instead add the name of the class to existing names like:

  obj.className = obj.className + "blank";  

Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -