需要一个快速的 jquery 解决方案来捕获当前 url 并将其注入到另一个 url 链接中
我的大脑被 ATM 机烧坏了,我的截止日期迫在眉睫,我正在寻找一种方法来获取当前查看的页面 URL 并将其放入另一个链接中以用于书签/社交链接。
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 Upon link:http://www.stumbleupon.com/submit?url=[PAGEURL]
Digg link: http://digg.com/submit?phase=2&url=[PAGEURL]
我需要将 [PAGEURL] 替换为正在查看的页面的 URL。任何帮助都是非常感激的。我已经寻找了一段时间,似乎无法找到适合这种特定情况的答案。
My brain is fried ATM and I have a looming deadline, I am looking for a way to grab the currently viewed pages url and place it into another link for bookmarking/social links.
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 Upon link:http://www.stumbleupon.com/submit?url=[PAGEURL]
Digg link: http://digg.com/submit?phase=2&url=[PAGEURL]
I need to replace [PAGEURL] with the URL for the page being viewed. Any help is most appreciate. i have been looking for a while now and can't seems to find an answer that fits this specific circumstance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
了解这些链接的结构会有所帮助。但是,这里有一些 jQuery 可能会为您指明一个好的方向。它假设您的社交书签链接位于带有
id="socials"
的容器中,但您可以混合选择器来执行任何操作来获取您的社交链接。这使用 attr 函数来获取链接指向的位置,然后使用正则表达式 ( eww!) 检查链接中是否包含 [PAGEURL],并将 [PAGEURL] 替换为 location.href,即当前页面的 url。这是一个方便的正则表达式测试器。
It'd help to see what kind of structure those links are in. But, here's some jQuery that might point you in a good direction. It assumes your social bookmarking links are in a container with
id="socials"
, but you can mash the selector to do whatever it takes to get hold of your social links.This uses the attr function to get where the link points to, then a regular expression (eww!) to check if the link has [PAGEURL] in it, and to replace [PAGEURL] with location.href, which is the url of the current page. Here's a handy regexp tester.
window.location.href
应该可以工作。window.location.href
should work.我想它会是这样的
I imagine it would be something like