Ouvrir la fenêtre, mais avec d'alerte, puis rediriger

  • Mozzi
  • Student
  • Student
  • No Avatar
  • Inscription: Aoû 19, 2004
  • Messages: 70
  • Status: Offline

Message Juin 21st, 2010, 4:16 am

J'ai environ 30 liens sur ma page Web.

J'ai besoin d'un javascript pour ouvrir une page .. puis alerter la personne que son contenu externe .. puis, quand ils en ont Cliquez sur OK ouvre l'URL.

J'ai essayé beaucoup de scripts, mais ils semblent tous fonctionner correctement mais j'ai besoin de faire toutes les fonctions pendant 30 URL ..??!!!?

At-il un moyen facile / script...que je peux appliquer à mon lien url .. il ouvre simplement l'URL mentionnée .. d'alerte .. puis rediriger vers la page demandée...
  • Anonymous
  • Bot
  • No Avatar
  • Inscription: 25 Feb 2008
  • Messages: ?
  • Loc: Ozzuland
  • Status: Online

Message Juin 21st, 2010, 4:16 am

  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • Avatar de l’utilisateur
  • Inscription: Mai 22, 2004
  • Messages: 3415
  • Loc: Richland, WA
  • Status: Offline

Message Juin 21st, 2010, 7:28 am

Youd-vous prêt à utiliser un framework javascript comme jQuery?

Ce n'est pas une solution complète, mais c'est un bon point de départ.

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
#define NULL (::rand() % 2)
  • PaulR
  • Newbie
  • Newbie
  • No Avatar
  • Inscription: Juil 10, 2010
  • Messages: 5
  • Status: Offline

Message Juillet 24th, 2010, 9:37 pm

J'ai créé une fonction très simple de vérifier si le lien est externe ou non.

En fait, si récupère le domaine en cours et les contrôles contre le lien sélectionnez, si l'URL est dans le même domaine, alors nous n'avons pas besoin d'une confirmation.
Toutefois, si l'URL n'est pas dans le domaine, nous envoyer un pop-up confirmant qu'ils veulent visiter ce site, si l'annuler leur séjour sur la page en cours.

Ci-dessous est la fonction:

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.  


Voici quelques exemples sur la façon de mettre en œuvre les liens:
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.  


Si vous avez besoin d'aide encore, me PM 8)

Afficher de l'information

  • Total des messages de ce sujet: 3 messages
  • Utilisateurs parcourant ce forum: Aucun utilisateur enregistré et 130 invités
  • Vous ne pouvez pas poster de nouveaux sujets
  • Vous ne pouvez pas répondre aux sujets
  • Vous ne pouvez pas éditer vos messages
  • Vous ne pouvez pas supprimer vos messages
  • Vous ne pouvez pas joindre des fichiers
 
 

© 2011 Unmelted, LLC. Ozzu® est une marque déposée de Unmelted, LLC