JavaScript: Get anchor from URL JavaScript: Вземи котва от URL
Posted on 10. Публикувано на 10. Jun, 2009 by Dragos in Apps , Coding , JavaScript & Ajax , PHP Юни, 2009 от Драгош в Apps, кодиране, JavaScript & Ajax, PHP
To get the anchor from an URL (this is the text after the # character) in JavaScript you can use the following code: За да получите котва от URL (това е текстът след # характер) в JavaScript можете да използвате следния код:
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 # коментар-1" / / ако имате нужда да се вземе текущата URL на прозореца на употреба: VAR URL = window.location; var anchor=url.hash; //anchor with the # character VAR котва = url.hash / / котва с # характер var anchor2=url.hash.substring(1); //anchor without the # character VAR anchor2 = url.hash.substring (1); / / котва без символа #
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: Ако сте iterating чрез връзките в една страница с JQuery и $ (тази) определя една връзка, а след това да се намери на стабилизиращ фактор на този обект, който ще трябва да използвате следния код:
var anchor=$(this).attr("hash"); VAR котва = $ (това). attr ( "хеш"); Related posts: Свързани пунктове:
- JavaScript: How to get the index (position within a group) of an object with jQuery? JavaScript: Как да отида на индекса (позиция в група) на обект с JQuery?
- Javascript: How to validate email address with JavaScript? Javascript: Как да се валидира имейл адрес с JavaScript?
- JavaScript: Send function as a parameter to another function (callbacks) JavaScript: Изпрати функция като параметър на друга функция (Callbacks)
- JavaScript: What if jQuery animation doesn't fire/start? JavaScript: Какво става, ако не Jquery анимация пожар на проекта?
- JavaScript: Where do I Find All Properties for All HTML Elements ? JavaScript: Къде мога да намеря всички имоти за всички елементи, HTML?












































