2014-09-29 83 views
0

的返回参数我有一个jQuery函数来检查是否支持Flash:获取jQuery函数内blade.php Laravel

<script type="text/javascript"> 
    $(document).ready(function(){ 

     function isFlashEnabled() 
      { 
       var hasFlash = false; 
       try 
       { 
        var fo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash'); 
        if(fo) hasFlash = true; 
       } 
       catch(e) 
       { 
        if(navigator.mimeTypes ["application/x-shockwave-flash"] != undefined) hasFlash = true; 
       } 
       return hasFlash; 
      } 

    }); 
</script> 

我希望得到我的页面返回hasFlash变量值(或真或假)。 blade.php并检查内部“@if”助手是否启用了闪光灯:

@if (hasFlash()) 
//if Flash is Enabled do this 
@else 
//do anything 
@endif 

这是正确的方法吗?

再次感谢

回答

0

好JavaScript不能用PHP直接合作! 你需要自己做一些Ajax的东西,或者用javascript和html的混合编写你的代码。 代替:

@if (hasFlash()) 
//if Flash is Enabled do this 
@else 
//do anything 
@endif 
在JavaScript

做:

if (hasFlash()){ 
// ajax/cal a php page directly for this function 
// you can bypass arguments from js (easier but not secure) or use database & session (hard to do but secure) 
}else{ 
// ajax/cal another php page directly for this function 
// parameter bypass is the same as above 
} 

,或者如果你的代码更简单,那么你可以只是JS写它直接。

你也可以使用jQuery和使用AJAX操纵网页(HTML)从PHP获取内容并把它添加到页面

编辑:好让我有样品塞纳里奥解释:
比方说,当闪光灯已启用,您希望拥有闪光灯播放器内容,并且在禁用闪光灯时,您想显示公证文本。
我想你想做的事是这样的:

@if (hasFlash()) 
    //if Flash is Enabled do this 
    echo '<media........>'; //whatever you html is. 
@else 
    echo '<p>Your flash disabled. ...</p>'; //whatever your error is. 
@endif 
解决此问题

最简单的办法,那我建议,是要操纵你的HTML你检测后客户端没有闪光灯,这样的:

在HTML :

您的闪存被禁用。 ...

,并在Javascript:

<script type="text/javascript"> 
    function isFlashEnabled() { 
     var hasFlash = false; 
     try { 
      var fo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash'); 
      if (fo) hasFlash = true; 
     } catch (e) { 
      if (navigator.mimeTypes ["application/x-shockwave-flash"] != undefined) hasFlash = true; 
     } 
     return hasFlash; 
    } 
    $(document).ready(function() { 
     if(!isFlashEnabled()){ 
      $('#flash_container').css('display','none'); 
      $('#no_flash_container').css('display',''); 
     } 
    }); 
</script> 

但是,你要调用一些PHP函数,当用户没有FALSH,那么你应该这样做:1。 创建一个PHP文件与你的功能。 2.在javascript中运行$.get('url to php file created in 1'); if。 3.使用session/database/http_params在你的页面之间传输php变量。

如果您仍然需要更多帮助,我认为最好先阅读一些文档/维基。

+0

嗯,我不明白... – 2014-09-29 14:02:34