[英]Why does the Pinterest code change the page (URL) displayed in the browser?
So I have spent a long time trying to find a Pinterest Pin It button that has both a counter AND allows me to choose any image from the page when I click on it. 所以我花了很长时间试图找到一个既有计数器又允许我单击该页面上的任何图像的Pinterest Pin It按钮。
The Pinterest code supplied by Pinterest requires you to specify a specific image to be shared, but it has a count. Pinterest提供的Pinterest代码要求您指定要共享的特定图像,但是它具有计数。
The Pinterest browser button can be adopted to use on a page and will bring up a javascript window allowing the user to choose any suitable image on the page, but it has no count. 可以采用Pinterest浏览器按钮在页面上使用,它将弹出一个javascript窗口,允许用户在页面上选择任何合适的图像,但是没有计数。
I've been playing around and searching and am very close. 我一直在玩耍并搜索,并且非常接近。 I have this code which is some of my own and some I've found on other sites: 我有以下代码,这是我自己的代码,也可以在其他网站上找到:
<a class='pin-it-button' count-layout='horizontal' href='http://pinterest.com/pin/create/button/?url={Encoded URL of Current Page}'>Pin It</a>
<a href='javascript:void(run_pinmarklet())' style='margin-left:-93px; width:43px; height:20px; display:inline-block;'/></a>
<script src='http://assets.pinterest.com/js/pinit.js' type='text/javascript'/>
<script type='text/javascript'>
function run_pinmarklet() {
var e=document.createElement('script');
e.setAttribute('type','text/javascript');
e.setAttribute('charset','UTF-8');
e.setAttribute('src','http://assets.pinterest.com/js/pinmarklet.js?r=' + Math.random()*99999999);
document.body.appendChild(e);
}
</script>
What this is doing is basically cheating by having the count button but then putting the code that lets a user choose an image an an element directly on top of the original button. 这基本上是在通过使用计数按钮来作弊,然后将使用户选择图像和元素的代码直接放在原始按钮的顶部。 A user thinks he is clicking on the Pin It button but is clicking on an that runs the javascript run_pinkarklet(). 用户认为自己正在单击“固定”按钮,但是单击的是运行javascript run_pinkarklet()的。
This works, however after I get the pop-over to choose an image, and I do choose the image, it then gets inserted into a pop-up window to complete the pinning, which works- but in the mean time the main page in the browser reloads. 此方法有效,但是在我获得弹出窗口以选择图像后,并且确实选择了图像,然后将其插入到弹出窗口中以完成固定,此操作有效,但与此同时,浏览器重新加载。 It doesn't reload the original page but it reloads the main URL of the current folder. 它不会重新加载原始页面,但会重新加载当前文件夹的主URL。
Example- suppose the page I am pinning is: http://www.example.com/folder1/page1.php 示例-假设我固定的页面为: http : //www.example.com/folder1/page1.php
It reloads to- http://www.example.com/folder1/ 它会重新加载到-http ://www.example.com/folder1/
I can't find any way to stop this reloading or to get it to at least reload the source page. 我找不到停止这种重新加载或至少使其重新加载源页面的任何方法。
I've confirmed this behavior on latest Chrome and Firefox. 我已经在最新的Chrome和Firefox上确认了此行为。
Any ideas? 有任何想法吗?
Pinterest的Widget构建器现在支持any image选项。
将onclick事件中的URL值设置为cookie变量。您可以访问cookie值,使用cookie值并重定向页面。
javascript:void((function(){var%20e = document.createElement('script'); e.setAttribute('type','text / javascript'); e.setAttribute('charset','UTF-8' ); e.setAttribute('src','http://assets.pinterest.com/js/pinmarklet.js?r ='+ Math.random()* 99999999); document.body.appendChild(e)}) ());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.