JavaScript: Get anchor from URL JavaScript: Obtenir l'àncora de l'URL
Posted on 10. Publicat a 10. Jun, 2009 by Dragos in Apps , Coding , JavaScript & Ajax , PHP Juny de 2009, per Dragos a Apps, codificació, JavaScript i Ajax, PHP
To get the anchor from an URL (this is the text after the # character) in JavaScript you can use the following code: Per obtenir l'àncora d'un URL (aquest és el text després del caràcter #) en JavaScript que pot utilitzar el següent codi:
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'; / / Si vostè necessita prendre la direcció actual de la utilització finestra: var url = window.location; var anchor=url.hash; //anchor with the # character àncora var = url.hash / / àncora amb el caràcter # var anchor2=url.hash.substring(1); //anchor without the # character var anchor2 = url.hash.substring (1); / / àncora sense el caràcter #
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: Si vostè és iterar a través dels enllaços en una pàgina amb jQuery, i $ (this) es defineix un sol enllaç, després de trobar l'àncora d'aquest objecte, cal utilitzar el següent codi:
var anchor=$(this).attr("hash"); ancoratge var = $ (this). attr ( "hash"); Related posts: Llocs relacionats amb:
- JavaScript: How to get the index (position within a group) of an object with jQuery? JavaScript: Com obtenir l'índex (posició dins d'un grup) d'un objecte amb jQuery?
- Javascript: How to validate email address with JavaScript? Javascript: Com validar l'adreça de correu electrònic amb JavaScript?
- JavaScript: Send function as a parameter to another function (callbacks) JavaScript: Enviar funcionar com un paràmetre a una altra funció (callbacks)
- JavaScript: What if jQuery animation doesn't fire/start? JavaScript: Què passa si l'animació jQuery no es dispara / inici?
- JavaScript: Where do I Find All Properties for All HTML Elements ? JavaScript: On puc trobar totes les propietats de tots els elements HTML?












































