0

I recently redirected my website from www.unreadyanwilling.com to cros.land.

While the redirects went well, I wanted to see if there was a way to retain the likes and tweets that each post had earned.

I read that one way to do this is to replace the like button's URL with the old URL. The problem is I have a social plugin which doesn't allow me to change the individual URL of each like button.

I'm seeing if there is an easy snippet of code I can attach to the end of my post to change the iframe URL of the facebook like button from the new URL to the old URL

I'm trying it out on this page: http://cros.land/2013/11/technology-and-meditation/

I'm trying to use document.querySelectorAll() to find the iframe by its src attribute because there is no id or class for this iframe. After getting this element, I'd like to replace it with the old attribute.

So far this code doesn't seem to be working (I put it at the end of my post):

<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&amp;send=false&amp;layout=box_count&amp;width=50&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font=arial&amp;height=65"]");
oldInput.src = "//www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.unreadyandwilling.com%2F2013%2F11%2Ftechnology-and-meditation%2F&amp;send=false&amp;layout=box_count&amp;width=50&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font=arial&amp;height=65";
</script>

1 Answer 1

1

I was in troble few days ago. jquery provided me solution, here is the example , just filter it with your links.

<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>

One more think,In your code,there is double quote in another double quote, it will not work

<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&amp;send=false&amp;layout=box_count&amp;width=50&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font=arial&amp;height=65']");
oldInput.src = "//www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.unreadyandwilling.com%2F2013%2F11%2Ftechnology-and-meditation%2F&amp;send=false&amp;layout=box_count&amp;width=50&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font=arial&amp;height=65";
</script>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I like the above implementation but I'm not using jQuery on my site. I figured I wouldn't need to for such a simple operation...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.