JavaScript: Get anchor from URL JavaScript: Get anker van URL
Posted on 10. Geplaatst op 10. Jun, 2009 by Dragos in Apps , Coding , JavaScript & Ajax , PHP Juni, 2009 door Dragos in Apps, Coding, Javascript en Ajax, PHP
To get the anchor from an URL (this is the text after the # character) in JavaScript you can use the following code: Om het anker van een URL (dit is de tekst na het # karakter) in JavaScript kunt u de volgende code gebruiken:
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'; / / als u de huidige URL van het venster gebruik te nemen: var url = window.location; var anchor=url.hash; //anchor with the # character var anchor = url.hash / / anker met het # teken var anchor2=url.hash.substring(1); //anchor without the # character var anker2 = url.hash.substring (1); / / anker zonder het # teken
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: Als je itereren via de links op een pagina met JQuery, en $ (dit) definieert een enkele link, vervolgens op zoek naar het anker van dit object je zou moet de volgende code gebruiken:
var anchor=$(this).attr("hash"); var anchor = $ (this). attr ( "hash"); Related posts: Gerelateerde berichten:
- Javascript: How to validate email address with JavaScript? Javascript: Hoe te valideren e-mailadres met JavaScript?
- JavaScript: How to get the index (position within a group) of an object with jQuery? JavaScript: Hoe krijg ik de index (positie binnen een groep) van een object met jQuery?
- JavaScript: Send function as a parameter to another function (callbacks) JavaScript: Stuur functie als parameter aan een andere functie (callbacks)
- JavaScript: What if jQuery animation doesn't fire/start? JavaScript: Wat als jQuery animatie niet brand / start?
- JavaScript: GIFless animation. JavaScript: GIFless animatie. Animate images,logos with jQuery Animate beelden, logo's met jQuery












































