Saturday, 15 September 2012

javascript - Need a quick jquery solution to capture the current url and inject it into another url link -


My ATMs fried in my brain and I have a time limit, one way I can capture the currently viewed url URLs. Looking for bookmark / social links, put it in another link.

  Facebook link: http: //www.facebook.com/share.php? U = [PAGEURL] MySpace Link: http: //Www.myspace.com/Modules/PostTo/Pages/?u=[PAGEURL] Twitter link: http://twitter.com/home?status=Check+this+out : + [[PAGEURL] Stumble on Link: http: /www.stumbleupon.com/submit?url=[PAGEURL] Dig link: http://digg.com/submit?phase=2&url=[PAGEURL] < / Code> 

I need this to replace [PAGEURL] with the URL of the page visited. Any help appreciates that I am looking for a while and no such answer can be found that fit in this specific situation.

"post-text" itemprop = "text">

helps to see what kind of structure these links are. But, here's some jQuery that can tell you in a good direction. It assumes that your social bookmarking links are in a container with the id = "socials" , but for whatever you take to capture your social link, you can select the mash can do.

  $ (function () {var links = $ ('# socials a'), matchExp = / \ [PAGEURL] /, currentURL = location.href; links.each (function ) {Var currentHREF = $ (this) .attr ('href'); if (current HREF.match (match XP) {$ (this) .attr ('href', currentHREF location (match XP, current URL))}} );});  

It uses the function to get that link, where one indicates a link, then a regular expression (Eve!) To see if the link [PAGEURL ], And to replace [PAGEURL], Location.href, which is the URL of the current page, is here


No comments:

Post a Comment