我正在编写一个允许用户在线处理图像的应用程序。到目前为止一切正常,但在某些网站上 - 他们没有使用 img 标签。所以我需要在右键单击时获取图像 url 的替代方法。
在 FHM.COM 他们有这个:
<div class="efImage" style="background-image: url('https://igcdn-photos-f-a.akamaihd.net/hphotos-ak-xpa1/t51.2885-15/e15/924583_1497100237194525_212104957_n.jpg');">
</div>
如何在右键单击时获取该图片的 url?
最佳答案
这个怎么样:-
$('*').mousedown(function(event) {
if(event.which == 3) { //detect right click
var background = $(this).css('background-image'); //get background image
if(/url\(([^\)]+)\)/.test(background)){ // check background image exists
var url = /url\(([^\)]+)\)/.exec(background)[1]; // get the url
alert(url);
}
}
});
关于Javascript - 如何从右键单击获取图像 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33335509/