JavaScript: Get anchor from URL JavaScript: Obtener el ancla de la URL
Posted on 10. Publicado en 10. Jun, 2009 by Dragos in Apps , Coding , JavaScript & Ajax , PHP Junio de 2009, por Dragos en Apps, codificación, JavaScript y Ajax, PHP
To get the anchor from an URL (this is the text after the # character) in JavaScript you can use the following code: Para obtener el ancla de una URL (este es el texto después del carácter #) en JavaScript que puede utilizar el siguiente código:
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 usted necesita tomar la dirección actual de la utilización ventana: var url = window.location; var anchor=url.hash; //anchor with the # character ancla var = url.hash / / ancla con el carácter # var anchor2=url.hash.substring(1); //anchor without the # character var anchor2 = url.hash.substring (1); / / ancla sin 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 usted es iterar a través de los enlaces en una página con jQuery, y $ (this) se define un solo enlace, luego de encontrar el ancla de este objeto, se necesitaría usar el siguiente código:
var anchor=$(this).attr("hash"); anclaje var = $ (this). attr ( "hash"); Related posts: Puestos relacionados con:
- JavaScript: How to get the index (position within a group) of an object with jQuery? JavaScript: Cómo obtener el índice (posición dentro de un grupo) de un objeto con jQuery?
- Javascript: How to validate email address with JavaScript? Javascript: Cómo validar la dirección de correo electrónico con JavaScript?
- JavaScript: Send function as a parameter to another function (callbacks) JavaScript: Enviar funcionar como un parámetro a otra función (callbacks)
- JavaScript: What if jQuery animation doesn't fire/start? JavaScript: ¿Qué pasa si la animación jQuery no se dispara / inicio?
- JavaScript: Where do I Find All Properties for All HTML Elements ? JavaScript: ¿Dónde puedo encontrar todas las propiedades de todos los elementos HTML?












































