javascript - 动态更改标题中的元标记?
问题描述
我正在使用一个按钮创建一个可共享的连接,我之前单击的按钮将执行一项功能,该功能在将 OPEN GRAPH 发布到社交媒体后对其进行修改。我尝试单击按钮并使用共享 API 与社交媒体共享,但标题、链接、缩略图和描述没有改变。
const share = $("#change").click(()=>{
$("meta[name=description]").remove();
$("head").append("<meta name='description' content='new description'>"
);})
解决方案
您可以使用此更改元标记
$('button').on('click', function() {
$('meta[name=description]').remove();
$('head').append( '<meta name="description" content="this is new">' );
console.log($('meta[name=description]').attr('content'));
});
<head>
<meta name="description"content="this is old">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<button>Change Meta</button>
推荐阅读
- python - 连接熊猫数据框中较早行的值
- woocommerce - 如何在 woocommerce 单品页面的选项卡部分之后(以及“您可能还喜欢...”部分之前)添加自定义内容?
- python-3.x - 出现错误:函数不可迭代。我该如何解决
- python - Vault - 如何使用 HVAC 从 kv v2 秘密引擎上的特定路径列出文件夹?
- java - 无法在 java 中解析 Protobuf
- visual-studio-code - 建议在visual studio代码中检测文件更改的方法
- reactjs - 输入后如何自动提交文本?
- cmd - 如何在命令行的宽度上创建一个字符行?
- clojure - 从函数中提取文档字符串
- php - 通过前缀转换成不同的货币