JavaScript: Get anchor from URL JavaScript: Få ankare från URL
Posted on 10. Inlagd den 10. Jun, 2009 by Dragos in Apps , Coding , JavaScript & Ajax , PHP Juni, 2009 av Dragos i Apps, Coding, JavaScript och Ajax, PHP
To get the anchor from an URL (this is the text after the # character) in JavaScript you can use the following code: För att få ankaret från en webbadress (detta är texten efter # tecknet) i JavaScript kan du använda följande kod:
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 ", / / om du behöver ta den aktuella webbadressen i fönstret användning: var url = window.location; var anchor=url.hash; //anchor with the # character Var ankare = url.hash; / / ankare med tecknet # var anchor2=url.hash.substring(1); //anchor without the # character Var anchor2 = url.hash.substring (1), / / ankare utan # tecken
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: Om du iteration genom länkarna på en sida med jQuery och $ (denna) definierar en enda länk, sedan hitta ankaret för detta objekt du behöver använda följande kod:
var anchor=$(this).attr("hash"); Var ankare = $ (this). attr ( "hash"); Related posts: Relaterade tjänster:
- JavaScript: How to get the index (position within a group) of an object with jQuery? JavaScript: Hur man får indexet (position inom en grupp) för ett objekt med jQuery?
- Javascript: How to validate email address with JavaScript? Javascript: Hur validera e-postadress med JavaScript?
- JavaScript: Send function as a parameter to another function (callbacks) JavaScript: Skicka fungera som en parameter till en annan funktion (callbacks)
- JavaScript: What if jQuery animation doesn't fire/start? JavaScript: Vad händer om jQuery animation inte eld / start?
- JavaScript: Where do I Find All Properties for All HTML Elements ? JavaScript: Var hittar jag alla egenskaper för alla HTML-element?












































