我最近将我的网站从 www.unreadyanwilling.com 重定向到 cros.land。
虽然重定向进展顺利,但我想看看是否有办法保留每个帖子获得的点赞和推文。
我读到,执行此操作的一种方法是将“赞”按钮的 URL 替换为旧 URL。问题是我有一个社交插件,它不允许我更改每个点赞按钮的单独 URL。
我正在查看是否有一个简单的代码片段可以附加到我的帖子末尾,以将 facebook like 按钮的 iframe URL 从新 URL 更改为旧 URL
我正在此页面上尝试:http://cros.land/2013/11/technology-and-meditation/
我尝试使用 document.querySelectorAll() 通过其 src 属性查找 iframe,因为该 iframe 没有 id 或类。获取此元素后,我想将其替换为旧属性。
到目前为止,这段代码似乎不起作用(我把它放在帖子的末尾):
<script type="text/javascript">
var oldInput = document.querySelectorAll("[src="//www.facebook.com/plugins/like.php?href=http%3A%2F%2Fcros.land%2F2013%2F11%2Ftechnology-and-meditation%2F&send=false&layout=box_count&width=50&show_faces=false&action=like&colorscheme=light&font=arial&height=65"]");
oldInput.src = "//www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.unreadyandwilling.com%2F2013%2F11%2Ftechnology-and-meditation%2F&send=false&layout=box_count&width=50&show_faces=false&action=like&colorscheme=light&font=arial&height=65";
</script>
最佳答案
前几天我遇到了麻烦。 jquery 为我提供了解决方案,这里是示例,只需用链接过滤它即可。
<script>
jQuery(document).ready(function(){
var iframe_src=jQuery("iframe[src*='http://player.vimeo.com/']").attr("src");
jQuery("iframe[src*='http://player.vimeo.com/']").attr("src",iframe_src+"&autoplay=1");
});
</script>
再想一想,在你的代码中,在另一个双引号中存在双引号,这是行不通的
<script type="text/javascript">
var oldInput = document.querySelectorAll("[src='//www.facebook.com/plugins/like.php?href=http%3A%2F%2Fcros.land%2F2013%2F11%2Ftechnology-and-meditation%2F&send=false&layout=box_count&width=50&show_faces=false&action=like&colorscheme=light&font=arial&height=65']");
oldInput.src = "//www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.unreadyandwilling.com%2F2013%2F11%2Ftechnology-and-meditation%2F&send=false&layout=box_count&width=50&show_faces=false&action=like&colorscheme=light&font=arial&height=65";
</script>
关于Javascript:在 WordPress 中查找并替换 Iframe URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24854091/