reload a flash object every x

Discussion in 'Programming' started by mhrlive, Nov 27, 2011.

  1. #1
    Hello,
    Can anyone help me with a JS function or anything else to reload automatically a flash swf object on my website every x min ?

    Thanks
     
    mhrlive, Nov 27, 2011 IP
  2. mhrlive

    mhrlive Active Member

    Messages:
    64
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    73
    #2
    helloo , is this hard to do or what :/
     
    mhrlive, Nov 28, 2011 IP
  3. proactiv3

    proactiv3 Peon

    Messages:
    55
    Likes Received:
    7
    Best Answers:
    4
    Trophy Points:
    0
    #3
    <!doctype html>
    <html>
    <head>
    	<title>Test</title>
    </head>
    <body>
    	<img id="swfobject" src="image.jpg" />
    
    <script type="text/javascript">
    	
    	function reloadSwf(element) {
    		console.log(element)
    		var el 		= document.getElementById(element);
    		var elSrc	= el.getAttribute("src");
    		var rand 	= '';
    		
    		setInterval(function() {
    			for(var i = 0; i <= 15; i++) {
    				rand += Math.floor( Math.random() * 10 ) + 1;
    			}
    			
    			el.setAttribute("src", elSrc + "?" + rand);
    		}, 5000);
    	}
    	
    	var id = "swfobject";
    	
    	if(document.addEventListener) {
    		document.addEventListener("DOMContentLoaded", function() {
    			document.removeEventListener("DOMContentLoaded", arguments.callee, false);
    			reloadSwf(id);
    		}, false);
    	} else {
    		document.attachEvent("onreadystatechange", function() {
    			if(document.readyState === "complete") {
    				document.detachEvent("onreadystatechange", arguments.callee);
    				reloadSwf(id);
    			}
    		});
    	}
    </script>
    </body>
    </html>
    Code (markup):
    Tested @ Webkit (Chrome). The idea is pretty simple - from time to time append a random string to the object's original source and reload the element. This will force the browser to completely reload the swf as it will be triggered to think that its a different object.

    I've used an image as an example, but you can use it on any element that has a src attribute.

    Good luck!
     
    proactiv3, Nov 29, 2011 IP
    mhrlive likes this.
  4. mhrlive

    mhrlive Active Member

    Messages:
    64
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    73
    #4
    Big Thanksss I will try it :)
     
    mhrlive, Nov 29, 2011 IP