2010-07-31 5 views

Répondre

2

trouvé ceci:

//Create an object of all links 
var links = $('a'); 
//Parse each item in links object 
for (var a in links){ 
//This will allow the for iteration to give the actual link objects that are 
//referred to with numeric indexes and not objects that jQuery appends 
//Object 'a' should be a number 
    if(a == parseInt(a)){ 
     //Variable b is now the object that is links[a]; 
     var b = links[a]; 
     //Variable c is now variable b cast to jQuery so I can use built in jQuery functions 
     var c = $(b); 
     //Variable temp now contains the href of that link 
     var temp = c.attr('href'); 
     //This should filter out any anchors in the page or any links without an href 
     if(temp != undefined){ 
      //This checks to see if they are inline links, mailto link, OR absolute link 
      //This isn't perfect in the case that your link was 'mailsomething.php' or any non http link (ftp or other protocol) 
      //The correct scenario here is to use regex but I didn't have the patience 
      //or time to do so, so I didn't plus I knew my links didn't apply to these caveats 
      var test = temp.substring(0,4); 
      if(test != 'mail' && test != 'http' && test != '#'){ 
       //Now we prepend the abosulte url with the proper and add the relative file location 
       c.attr('href','http://differentsubdomain.domain.com/'+temp); 
      } 
     } 
    } 
} 

sur cette page:

Rewrite all links on a page...

+0

cool.this works..thanks .. – Vamsi

+1

Si cela fonctionne , alors vous devriez lui attribuer la bonne réponse en cliquant sur la coche. –

0

Cela permet de sélectionner tous les points d'ancrage dans la page: $ ('a')

Cela définit l'attribut href. $ ('a') attr ('href', » ')

Je ne suis pas sûr de ce que cela serait nécessaire, tho.

1

Voici un exemple:

$("a").attr("href","anotherurl.html");