简体   繁体   English

无法使用Safari在生产站点上加载JavaScript

[英]JavaScript not loading on production site with Safari

JavaScript works fine both locally and production on Chrome, but when I try in Safari, it doesn't. JavaScript在本地 Chrome上都能正常工作,但是当我在Safari中尝试时,JavaScript却无法正常工作。 I would think the solution would be to enable JavaScript on Safari, but I do have it enabled, and it's working locally on Safari. 我认为解决方案是在Safari上启用JavaScript,但是我确实启用了它,并且它在Safari上本地工作。 It just doesn't work on production. 只是在生产上不起作用。 I would think there's a problem with how I'm pushing up to production, but my production environment is working on Chrome. 我认为我如何进行生产会有问题,但是我的生产环境正在Chrome上运行。

I'm using Rails with jQuery Turbolinks. 我在jQuery Turbolinks中使用Rails。

My application.js: 我的application.js:

//= require jquery
//= require jquery.turbolinks
//= require jquery_ujs
//= require bootstrap
//= require social-share-button
//= require zeroclipboard
//= require google_analytics
//= require turbolinks
//= require_tree .

A sample JS file that isn't loading correctly: 无法正确加载的示例JS文件:

$(document).ready(function() {
  var referLinkClip = new ZeroClipboard($("#referral-text-button"))
  var referCodeClip = new ZeroClipboard($("#referral-code-button"))
  var embedClip = new ZeroClipboard($("#embed-text-button"))
  alert('foobar');
  $(".copy-button").hover(function(){
    $(this).css('background-color', '#7b7b7b');
    }, function(){
    $(this).css("background-color", '#949494');
  });
  $(".copy-button").click(function(){
    $(this).css('outline', 'none');
    $(this).css('background-color', '#2d3538');
    setTimeout(function(){
      $(this).css('background-color', '#949494');
    }, 100);
  });
});

My view using this JS (HAML): 我使用此JS(HAML)的视图:

%button#referral-code-button.plan-show.round-corners-8px.col-md-2.referral-links.copy-button{:'data-clipboard-target'=>'referral-code'}
  Copy code
.plan-show.round-corners-8px.col-md-8.referral-links.light-text
  Your affiliate code:
  %span#referral-code.medium-text= "#{current_user.affiliate_code}"

This all works fine in Chrome locally and on production, but just not on production in Safari. 所有这些都可以在Chrome本地和生产环境中很好地工作,但在Safari中则不能。 I've compiled my assets with bundle exec rake assets:precompile , and it makes no difference. 我已经用bundle exec rake assets:precompile编译了我的资产,这没有什么区别。

Any ideas? 有任何想法吗? I'm stumped. 我很沮丧

Edit: 编辑:

More info that may prove useful... Recently, even on Chrome, I've had trouble getting the JS to load properly unless the page is refreshed. 可能证明有用的更多信息...最近,即使在Chrome上,除非刷新页面,否则我都无法正确加载JS。 In the JS file I provided, the $(".copy-button").click function works (button changes color), but neither the $(".copy-button").hover works, nor do the ZeroClipboard objects initialize. 在我提供的JS文件中, $(".copy-button").click函数起作用(按钮更改颜色),但是$(".copy-button").hover ZeroClipboard对象也未初始化。 I'm including the JS in my application.html head, with =javascript_include_tag 'application' 我将JavaScript包含在我的application.html头中,并带有=javascript_include_tag 'application'

I encountered a similar issue (see Safari iOS not loading Javascript file? ) and found that the reason was Safari automatically sandboxing (blocking all JS execution) on requests done using HTTP/0.9. 我遇到了类似的问题(请参阅Safari iOS是否不加载Javascript文件? ),发现原因是Safari对使用HTTP / 0.9完成的请求进行了自动沙箱处理(阻止了所有JS执行)。

For more details check out my answer in the other thread. 有关更多详细信息,请在另一个线程中查看我的答案。

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

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