This is a translated page. The original can be found here: http://iwebdevel.com/2009/06/10/javascript-get-anchor-from-url/
UPDATES VIA RSS | Email Opdateringer via RSS | E-mail Get updates via feedburner Get updates via twitter
Home / Apps / Coding / JavaScript & Ajax / PHP / JavaScript: Get anchor from … Home / Apps / Kodning / JavaScript & Ajax / PHP / JavaScript: Få anker fra ...

JavaScript: Get anchor from URL JavaScript: Få anker fra webadresse

Posted on 10. Sendt den 10. Jun, 2009 by Dragos in Apps , Coding , JavaScript & Ajax , PHP Juni, 2009 af Dragos i Apps, Kodning, JavaScript og Ajax, PHP

To get the anchor from an URL (this is the text after the # character) in JavaScript you can use the following code: For at få ankeret fra en webadresse (dette er den tekst efter #-tegn) i JavaScript, kan du bruge følgende kode:

 var url='http://iwebdevel.com/some-post#comment-1'; //if you need to take the current url of the window use: var url=window.location; var url = 'http://iwebdevel.com/some-post # comment-1'; / / hvis du har brug for at tage den aktuelle url af vinduet brug: var url = window.location;
var anchor=url.hash; //anchor with the # character var anchor = url.hash; / / anker med # karakter
var anchor2=url.hash.substring(1); //anchor without the # character var anchor2 = url.hash.substring (1) / / anker uden # karakter 

If you're iterating through the links in a page with JQuery, and $(this) defines a single link, then to find the anchor of this object you'd need to use the following code: Hvis du iteration gennem links i en side med jQuery, og $ (denne) definerer et enkelt link, så at finde anker af dette objekt, du vil bruge følgende kode:

 var anchor=$(this).attr("hash"); var anker = $ (denne). attr ( "hash"); 
Translate this post Oversæt dette indlæg


Related posts: Relaterede stillinger:

  1. Javascript: How to validate email address with JavaScript? Javascript: Hvordan at validere e-mail-adresse med JavaScript?
  2. JavaScript: How to get the index (position within a group) of an object with jQuery? JavaScript: Sådan får du indekset (position inden for en gruppe) af et objekt med jQuery?
  3. JavaScript: Send function as a parameter to another function (callbacks) JavaScript: Send fungere som en parameter til en anden funktion (tilbagekald)
  4. JavaScript: What if jQuery animation doesn't fire/start? JavaScript: Hvad hvis jQuery animationen ikke brand / start?
  5. JavaScript: GIFless animation. JavaScript: GIFless animation. Animate images,logos with jQuery Animere billeder, logoer med jQuery

    blog comments powered by Disqus blog comments powered by Disqus