简体   繁体   English

如何使用JavaScript显示/隐藏Flash对象

[英]How to show/hide flash object using javascript

I want to embed this timer in a website. 我想将此计时器嵌入网站中。 Basically I generated a timer from this website . 基本上,我从该网站生成了一个计时器。 Then I would use this code and inject it to an html page. 然后,我将使用此代码并将其注入到html页面。 The code works great, however I only want to use this timer for some specific case (ie, using if-else) as followed: 代码效果很好,但是我只想在某些特定情况下(例如,使用if-else)使用此计时器,如下所示:

<script> 

flash = '<object type=&quot;application/x-shockwave-flash&quot; data=&quot;http://www.oneplusyou.com/bb/files/countdown/countdown.swf?co=000000&bgcolor=ffffff&date_month=10&date_day=26&date_year=0&un=DEAL ENDS&size=normal&mo=10&da=26&yr=2014&quot; width=&quot;250&quot; height=&quot;100&quot;><param name=&quot;movie&quot; value=&quot;http://www.oneplusyou.com/bb/files/countdown/countdown.swf?co=000000&bgcolor=ffffff&date_month=10&date_day=26&date_year=0&un=DEAL ENDS&size=normal&mo=10&da=26&yr=2014&quot; /><param name=&quot;bgcolor&quot; value=&quot;#ffffff&quot; /></object>';`

    if (new Date().getHours() < 20) {
        document.write(flash);
    }

</script>

But then I'll get this error no plugin available to display this content 但是然后我会收到此错误, no plugin available to display this content

So how would I built something like this another way, or maybe there's a fix for this 因此,我将如何以其他方式构建类似的内容,或者对此有解决方法

THanks 谢谢

I'll propose 2 options and I'm sure there is bunch more out there. 我将提出2个选择,我敢肯定还有很多选择。 First one should work with your flash option.... 第一个应该使用您的Flash选项。

OPTION 1 First put your flash object on the page with style display:none . 选项1首先将您的Flash对象放在样式为display:none的页面上。 Then in your javascript you evaluate if it's time to show it. 然后在您的JavaScript中评估是否应该显示它。

HTML EXAMPLE 1: HTML示例1:

<object id="myCountdown" style="display:none;" width="400" height="50" data="path-to-your-flash.swf"></object>

HTML EXAMPLE 2 with classes and css - prefered: 具有类和CSS的HTML示例2-首选:

<object id="myCountdown" class="hidden" width="400" height="50" data="path-to-your-flash.swf"></object>

CSS: CSS:

.hidden{display:none;}

JS: JS:

if(new Date().getHours() < 20){
   $('#myCountdown').css('display', 'block'); //using jQuery for first example

//OR

   $('#myCountdown').removeClass('hidden'); //using jQuery exmaple 2
}

OPTION 2: 选项2:

Talking about building it another way I would use a plugin: COUNTDOWN.JS 谈论以另一种方式使用插件来构建它: COUNTDOWN.JS

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

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