简体   繁体   English

Javascript后台URL图像未显示在Safari浏览器上

[英]Javascript background URL image NOT showing up on Safari browser

Im trying to display a products image in Javascript, like this: 我试图在Javascript中显示产品图像,如下所示:

  <script>
      $(document).ready(function(){

        var image,caption;

        function sectionHtml(caption,image){
          return '<div class="mason-image" style="background: url('+image+') center center; background-size: cover;"><h3>'+ caption +'</h3></div>';
        }

        caption = $($('.image-bar__item')[0]).text()
        image = $($('.image-bar__item.image-bar__link')[0]).css('background-image').replace('url("','').replace('")','')


// More stuff here, not related to image
 });
</script>

The image shows up great on chrome, and Internet Explorer, but on Safari, the image does not show up. 图像在Chrome和Internet Explorer上显示效果很好,但在Safari上,图像不会显示。

Here is how the inspected code looks on Chrome Dev Tools: 以下是检查代码在Chrome开发工具上的显示方式:

在此输入图像描述

This is what shows up on Safari Developer console: 这是Safari Developer控制台上显示的内容:

在此输入图像描述

The "url" part shows up twice on safari, thats why its breaking. “url”部分在safari上显示两次,这就是为什么它会破坏。 Is there a way I can fix that so it does not show up twice on Safari? 有没有办法可以修复它,所以它不会在Safari上出现两次?

This is what I had to do to get it working: 这是我必须做的才能让它工作:

'<div class="mason-image" style="background: url(' + image + ') center center;"></div>';

image = $($('.image-bar__item.image-bar__link')[0]).css('background-image').replace('url','').replace('(','').replace(')','').replace('"','').replace('"','')

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

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