Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/419.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Pinterest javascript SDK pinOne方法弹出对话框_Javascript_Pinterest - Fatal编程技术网

Pinterest javascript SDK pinOne方法弹出对话框

Pinterest javascript SDK pinOne方法弹出对话框,javascript,pinterest,Javascript,Pinterest,下午好 上下文 我们正在使用Pintrest JavaScript SDK弹出一个对话框,在Pintrest上锁定某些内容 要求 我们希望弹出对话框显示在屏幕中央 问题 当前它正在工作,但对话框出现在错误的位置 代码 $.getScript('https://assets.pinterest.com/js/pinit.js,函数(){ var pinObj={ url:url, 媒体:ogImg.attr(“内容”) }; pinObj.description='description';

下午好

上下文

我们正在使用Pintrest JavaScript SDK弹出一个对话框,在Pintrest上锁定某些内容

要求

我们希望弹出对话框显示在屏幕中央

问题

当前它正在工作,但对话框出现在错误的位置

代码


$.getScript('https://assets.pinterest.com/js/pinit.js,函数(){
var pinObj={
url:url,
媒体:ogImg.attr(“内容”)
};
pinObj.description='description';

PinUtils.pinOne(pinObj);
所以您似乎是从

为了回答您的问题,我认为没有一种方法可以在打开对话框的地方进行沟通。这通常很难,因为根据屏幕大小甚至分辨率,很难确定“居中”的定义点

查看
pinOne的源代码

            pinOne: function(a) {
                if (a.href) {
                    var b = e.f.parse(a.href, {
                        url: !0,
                        media: !0,
                        description: !0
                    });
                    b.url && b.url.match(/^http/i) && b.media && b.media.match(/^http/i) ? (b.description || (e.f.log("&type=config_warning&warning_msg=no_description&href=" + encodeURIComponent(e.d.URL)), b.description = e.d.title), e.w.open(a.href, "pin" + (new Date).getTime(), e.a.pop.base.replace("%dim%", e.a.pop.small))) : (e.f.log("&type=config_error&error_msg=invalid_url&href=" + encodeURIComponent(e.d.URL)), e.f.util.pinAny())
                } else a.media ? (a.url || (e.f.log("&type=config_warning&warning_msg=no_url&href=" + encodeURIComponent(e.d.URL)), a.url = e.d.URL), a.description || (e.f.log("&type=config_warning&warning_msg=no_description&href=" + encodeURIComponent(e.d.URL)), a.description = e.d.title), e.f.log("&type=button_pinit_custom"), a.href = e.v.config.pinterest + "/pin/create/button/?guid=" + e.v.guid + "&url=" + encodeURIComponent(a.url) + "&media=" + encodeURIComponent(a.media) + "&description=" + encodeURIComponent(a.description), e.w.open(a.href, "pin" + (new Date).getTime(), e.a.pop.base.replace("%dim%", e.a.pop.small))) : (e.f.log("&type=config_error&error_msg=no_media&href=" + encodeURIComponent(e.d.URL)), e.f.util.pinAny());
                a.v && a.v.preventDefault ? a.v.preventDefault() : e.w.event.returnValue = !1
            },
提供给您的唯一真正的定制选项包括
url
媒体
,以及
说明
。似乎没有任何“中心化”的沟通方式

话虽如此,我认为这只是他们的小部件API的一个限制。如果你是硬编码一个特定的pinterest链接,你可能只需要创建自己的链接并传入
windowFeatures
。我在下面尝试过,它“有点”起作用(可能需要调整确定位置的逻辑)

document.getElementById('pinterest-link')。addEventListener('click',函数(e){
var URL=e.target.getAttribute('data-pin-myownlink');
//假设您想要一个450x450的弹出窗口
var w=450;
var h=450;
//抄袭http://www.nigraphic.com/blog/java-script/how-open-new-window-popup-center-screen
var dualScreenLeft=window.screenLeft!=未定义?window.screenLeft:screen.availLeft;
var dualScreenTop=window.screenTop!=未定义?window.screenTop:screen.availTop;
宽度=window.innerWidth?window.innerWidth:document.documentElement.clientWidth?document.documentElement.clientWidth:screen.width;
高度=window.innerHeight?window.innerHeight:document.documentElement.clientHeight?document.documentElement.clientHeight:screen.height;
左变量=((宽度/2)-(宽度/2))+dualScreenLeft;
变量顶部=((高度/2)-(高度/2))+双屏幕顶部;
打开(URL,“Pinterest链接”,“工具栏=否,位置=否,目录=否,状态=否,菜单栏=否,滚动条=否,可调整大小=否,复制历史=否,宽度='+宽度+',高度='+高度+',顶部='+顶部+',左侧='+左侧);
});

这正是我所期望的。实际上,我可以修改框架来添加该功能,但在此之前,我想知道是否有现成的解决方案。嗯,是的,老实说,所以通过JavaScript将弹出窗口居中的正常方法是只需传递正确的
顶部
左侧
协调。参见。您可以在他
pinOne
code有一个
e.w.open
正是它触发了弹出窗口,但它们没有给你额外的空间。不确定这有多容易,但你可能只需要提取URL并触发
窗口就可以逃脱。打开
yourself+传递功能。@MartinOuimet我创建了一个我在上面的评论?我不确定这是否是你应该做的,因为它非常粗糙。谢谢你,它帮助了你!:)