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 Uppdateringar via RSS | E-post Get updates via feedburner Get updates via twitter
Home / Apps / Coding / JavaScript & Ajax / PHP / JavaScript: Get anchor from … Hem / Apps / Kodning / JavaScript / Ajax / PHP / JavaScript: Få ankare från ...

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"); 
Translate this post Översätta det här inlägget


Related posts: Relaterade tjänster:

  1. 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?
  2. Javascript: How to validate email address with JavaScript? Javascript: Hur validera e-postadress med JavaScript?
  3. JavaScript: Send function as a parameter to another function (callbacks) JavaScript: Skicka fungera som en parameter till en annan funktion (callbacks)
  4. JavaScript: What if jQuery animation doesn't fire/start? JavaScript: Vad händer om jQuery animation inte eld / start?
  5. JavaScript: Where do I Find All Properties for All HTML Elements ? JavaScript: Var hittar jag alla egenskaper för alla HTML-element?

    blog comments powered by Disqus blogg kommentarer drivs av Disqus