简体   繁体   English

javascript:popWin对我的URL取消编码

[英]javascript:popWin un-encodes my URL

I'm trying to add social sharing buttons to a website I manage. 我正在尝试向我管理的网站添加社交共享按钮。 I have to use a new tab or popWin to do this as most of the social sites prevent being loaded via iframe (which prevents the use of modal popups). 我必须使用新的标签页或popWin来执行此操作,因为大多数社交网站都阻止通过iframe加载(这阻止了使用模式弹出式窗口)。

I settled on popWin because it would keep the user on my page. 我选择了popWin,因为它将使用户留在我的页面上。 The problem is that I'm still new to javascript and am not overly familiar with popWin. 问题是我对javascript还是很陌生,对popWin不太熟悉。 popWin appears to be un-encoding my URLs which works with most social sharing sites but tumbler has a problem with it. popWin似乎在取消对我的URL的编码,该URL适用于大多数社交共享网站,但是tumbler对此有问题。

If I remove popWin the URL opens a new tab and shares the product page as it should. 如果删除popWin,则URL将打开一个新选项卡并按需共享产品页面。

Can I force popWin to use my URL as is "url=http%3A%2F%2F" instead of "url=http://" 我可以强制popWin以“ url = http%3A%2F%2F”而不是“ url = http://”的形式使用我的URL

<a href="javascript:popWin('http://www.tumblr.com/share/link?url=<?php echo urlencode($productUrl); ?>', 'tumbler', 'width=640,height=480,left=0,top=0,location=no,status=yes,scrollbars=yes,resizable=yes');" title="Share Link Via Tumblr">Tumblr</a>

在javascript中使用encodeURIComponent

<a href="javascript:popWin(encodeURIComponent('http://www.tumblr.com/share/link?url=<?php echo urlencode($productUrl); ?>)', 'tumbler', 'width=640,height=480,left=0,top=0,location=no,status=yes,scrollbars=yes,resizable=yes');" title="Share Link Via Tumblr">Tumblr</a>

Found this after having the same problem with popWin and tumblr. 在与popWin和tumblr遇到相同的问题后发现了这一点。 I have modified Matt's answer to show how I did it. 我修改了Matt的答案以显示我是如何做到的。

<a href="javascript:popWin('http://www.tumblr.com/share/link?' + encodeURIComponent('url=<?php echo urlencode($productUrl); ?>')', 'tumblr', 'width=640,height=480,left=0,top=0,location=no,status=yes,scrollbars=yes,resizable=yes');" 
title="Share Link Via Tumblr">Tumblr</a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM