从图像创建弹出窗口

时间:2017-04-27 16:23:50

标签: javascript html wordpress

在我的网站上我有一个带有facebook图标的共享选项,当点击它在新页面中打开一个网页时,我想尝试在原始页面中实现一个弹出窗口但是具有相同的内容,是它是一种需要被调用的特定类型的目标吗?

这里我留下一个代码示例:

代码中的“_blank”是目标。

if(strpos($atts['on'], "fb") !== false) $html .= aTag("https://www.facebook.com/sharer/sharer.php?u=".$atts['href'], getImgTagByImageName($atts['fb-icon']), "_blank", $atts['id'], $atts['class']);

2 个答案:

答案 0 :(得分:1)

以下是创建弹出窗口的链接。https://www.w3schools.com/howto/howto_js_popup.asp
在你的情况下:

<div class="popup" onclick="myFunction()">Click me!
 <span class="popuptext" id="myPopup">Popup text...</span>//your image goes here
</div>

答案 1 :(得分:1)

尝试window.open(strUrl, strWindowName, [strWindowFeatures])

会是这样的:

window.open('http://fb.com', 'fbShareWindow', 'height=[HEIGHT], width=[WIDTH], top=[TOP], left=[LEFT], toolbar=0, location=0, menubar=0, directories=0, scrollbars=0');

在jsfiddle上尝试下面的代码段。它在这里不起作用,因为SO和Fiddle阻止包含弹出窗口的代码。

window.share = function() {
  window.open('http://fb.com', 'fbShareWindow', 'height=[HEIGHT], width=[WIDTH], top=[TOP], left=[LEFT], toolbar=0, location=0, menubar=0, directories=0, scrollbars=0');
}
<button onclick="share();">Share me</button>

参考:

https://developer.mozilla.org/en-US/docs/Web/API/Window/open