JavaScript: Get anchor from URL JavaScript: Get ankra mill-URL
Posted on 10. Posted on 10. Jun, 2009 by Dragos in Apps , Coding , JavaScript & Ajax , PHP Ġunju, 2009 minn Dragos fl apps, Kodifika, 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: Biex tikseb l-ankra minn URL (dan huwa t-test wara l-karattru #) fl JavaScript tista 'tuża l-kodiċi li ġejjin:
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; url var = "http://iwebdevel.com/some-post # comment-1"; / / jekk ikollok bżonn tieħu l-url attwali ta 'l-użu tieqa: var url = window.location; var anchor=url.hash; //anchor with the # character ankra var = url.hash; / / ankra mal-karattru # var anchor2=url.hash.substring(1); //anchor without the # character var anchor2 = url.hash.substring (1); / / ankra mingħajr il-karattru #
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: Jekk int mtennija permezz tar-rabtiet fil-paġna ma JQuery, u $ (dan) jiddefinixxi rabta waħda, allura biex issib l-ankra ta 'dan l-oġġett inti'd bżonn li jintuża l-kodiċi li ġej:
var anchor=$(this).attr("hash"); ankra var = $ (dan). attr ( "hash"); Related posts: Related postijiet:
- JavaScript: How to get the index (position within a group) of an object with jQuery? JavaScript: Kif tista 'tikseb l-indiċi (il-pożizzjoni fi ħdan grupp) ta' oġġett jQuery?
- Javascript: How to validate email address with JavaScript? Javascript: Kif biex jivvalida l-indirizz email bl JavaScript?
- JavaScript: Send function as a parameter to another function (callbacks) JavaScript: Send funzjoni bħala parametru ieħor għall-funzjoni (callbacks)
- JavaScript: What if jQuery animation doesn't fire/start? JavaScript: X'jiġri jekk jQuery animazzjoni ma 'nar / tibda?
- JavaScript: Where do I Find All Properties for All HTML Elements ? JavaScript: Fejn nista Find All Properties for All Elementi HTML?












































