Open window but with alert and then redirect

  • Mozzi
  • Student
  • Student
  • Mozzi
  • Posts: 70

Post 3+ Months Ago

I have about 30 links on my webpage.

I need a javascript to open a page.. then alert the person that its external content .. then when they click ok it opens the url.

I have tried many scripts but they all seem to work ok but i need to do all the functions for 30 urls..??!!!?

Is their a easy way / script... that i can apply to my url link.. so it just opens the url mentioned .. alert.. and then redirect to the page requested...
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

You'd you be willing to use a javascript framework such as Jquery?

This isnt a complete solution, but its a good starting point.

JAVASCRIPT Code: [ Select ]
// Creating custom :external selector
$.expr[':'].external = function(obj){
    return !obj.href.match(/^mailto\:/)
            && (obj.hostname != location.hostname);
};
 
// Add 'external' CSS class to all external links
$('a:external').addClass('external');
  1. // Creating custom :external selector
  2. $.expr[':'].external = function(obj){
  3.     return !obj.href.match(/^mailto\:/)
  4.             && (obj.hostname != location.hostname);
  5. };
  6.  
  7. // Add 'external' CSS class to all external links
  8. $('a:external').addClass('external');

http://jquery-howto.blogspot.com/2009/0 ... -with.html
  • PaulR
  • Newbie
  • Newbie
  • PaulR
  • Posts: 5

Post 3+ Months Ago

I have created a very simple function to check if the link is external or not.

Basically, if fetches the current Domain and checks it against the select link, if the URL is within the same domain, then we don't need a confirmation.
However if the URL is not within the Domain, we send a pop-up confirming they want to visit that site, if the cancel they stay on the current page.

Below is the function:

JAVASCRIPT Code: [ Select ]
function exLinks(URL){
  // Check the domain against the link.
  // If the link is not within the current Domain, prompt the user.
  if(!URL.indexOf(document.domain)!=-1) {
    msg = "This is an external link, are you sure you wish to visit this site?"; // Pop-up message, for confirmation.
 
    // If confirmed, redirect to the external website
    if(confirm(msg)) {
      window.location=URL;
    }
 
  } else {
    // If the URL is within the same domain, no confirmation needed.
    window.location=URL;
  }
}
 
  1. function exLinks(URL){
  2.   // Check the domain against the link.
  3.   // If the link is not within the current Domain, prompt the user.
  4.   if(!URL.indexOf(document.domain)!=-1) {
  5.     msg = "This is an external link, are you sure you wish to visit this site?"; // Pop-up message, for confirmation.
  6.  
  7.     // If confirmed, redirect to the external website
  8.     if(confirm(msg)) {
  9.       window.location=URL;
  10.     }
  11.  
  12.   } else {
  13.     // If the URL is within the same domain, no confirmation needed.
  14.     window.location=URL;
  15.   }
  16. }
  17.  


Here is a few samples on how to implement the links:
HTML Code: [ Select ]
<a onClick="exLinks('http://www.Ozzu.com');" href="javascript&#058;void();">www.ozzu.com</a><br>
<a onClick="exLinks('URL Here');" href="javascript&#058;void();">Link Here</a><br>
<a onClick="exLinks('URL Here');" href="javascript&#058;void();">Link Here</a>
 
  1. <a onClick="exLinks('http://www.Ozzu.com');" href="javascript&#058;void();">www.ozzu.com</a><br>
  2. <a onClick="exLinks('URL Here');" href="javascript&#058;void();">Link Here</a><br>
  3. <a onClick="exLinks('URL Here');" href="javascript&#058;void();">Link Here</a>
  4.  


If you need help still, PM me 8)

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 142 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.