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"); Related posts: Relaterede stillinger:
- Javascript: How to validate email address with JavaScript? Javascript: Hvordan at validere e-mail-adresse med JavaScript?
- 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?
- JavaScript: Send function as a parameter to another function (callbacks) JavaScript: Send fungere som en parameter til en anden funktion (tilbagekald)
- JavaScript: What if jQuery animation doesn't fire/start? JavaScript: Hvad hvis jQuery animationen ikke brand / start?
- JavaScript: GIFless animation. JavaScript: GIFless animation. Animate images,logos with jQuery Animere billeder, logoer med jQuery












































