在社交网络上共享页面锚点 [英] Sharing Page Anchors on Social Networks

查看:127
本文介绍了在社交网络上共享页面锚点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Wordpress创建了一个单页面网站,该页面使用页面上的锚进行导航,但是当共享这些链接时,所有社交网络似乎都会去掉网址的锚点部分。



有没有简单的方法呢?



另外,任何人都可以提供PHP或JavaScript代码,我可以在我的Wordpress网站上包含以便能够指向URL参数链接到已命名的锚。例如



http://example.com/?a =锚点
重定向到:
http://example.com/#anchor

谢谢!

解决方案

确切的问题描述了当我试图使用社交媒体共享插件共享特定链接时,我的单页网站上的链接链接被剥离出来。我最终使用Javascript来替换%23 这样的标签: ).ready(function(){
$('。social-media-links a')。each(function(){
this.href = this.href.replace('#',' %23');
});
});

这对我来说非常合适,现在我的主题标签以及我的链接链接保持不变,当人们尝试通过点击网站上的分享按钮分享它们。

以下是我撰写有关我的解决方案的博客文章的链接 - http://icode4you.net/how-to-preserve -anchor-tags-in-links-shared-using-a-social-media-sharing-plugin-on-a-one-page-website /

I'm using Wordpress to create a single paged site which uses anchors on the page for navigation, however when sharing these links all social networks appear to strip out the anchor portion of the URL.

Is there an easy way around this?

Alternatively could anyone provide PHP or JavaScript code I could include on my Wordpress site to be able to point URL arguments links to named anchors. e.g.

http://example.com/?a=anchor redirecting to: http://example.com/#anchor

Thanks!

解决方案

I ran into the same exact issue you describe where the anchor links on my one page site were being stripped out when I tried to share specific links using a social media sharing plugin. I ended up using Javascript to replace the hashtags with %23, like so:

$(document).ready(function(){
    $('.social-media-links a').each(function(){
        this.href = this.href.replace('#', '%23');
    });
});

And that worked perfectly for me, now my hashtags and therefore my anchor links stay intact when people try to share them by clicking a "share" button on the website.

Here is a link to the blog post I wrote about my solution - http://icode4you.net/how-to-preserve-anchor-tags-in-links-shared-using-a-social-media-sharing-plugin-on-a-one-page-website/.

这篇关于在社交网络上共享页面锚点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆