how do i make a flash element mobile friendly with javascript?

52 Views Asked by At

if I have a site that has a flash header, but it's not mobile friendly on apple products and even some androids, what is the javascript code I can insert into my .html page so that it doesn't show this when it is loaded...

What I'm trying to fix:

1

There are 1 best solutions below

0
VC.One On

You can try using HTML5's innerHTML option with JavaScript to check whether Flash is available or not. From that info, you could then show alternative content like some image file if the device cannot display an .swf file (Flash app).

Since you did not show any code of your own page header setup, I'll show a basic example and maybe you can apply logic to your own page.

  • Put code in blank document (edit widths/heights) and save as .html.

  • In your browser block Flash and refresh... it shows image banner.

  • In your browser **enable* Flash and refresh... it shows Flash banner.

Test this code and ask any questions for clarification:

<!DOCTYPE html>
<html>

<body> 

<div id="my_Banner"></div>

</body>


<script>

var show_A = '<embed width=600 height=200 src="https://www.w3schools.com/tags/helloworld.swf">';

var show_B = '<img width=600 height=200 src="https://www.videocopilot.net/blog/wp-content/uploads/2013/03/trap.jpg"/>';

function isFlashEnabled() 
{
    var flash = navigator.plugins.namedItem('Shockwave Flash');
    if (!flash) { return 0; } 
    else { return 1; }
}


if( isFlashEnabled() ) //if Flash is availabe as browser plugin
{ document.getElementById('my_Banner').innerHTML = show_A; } 

else //if Flash not availabe as browser plugin (eg: on mobile browsers)
{ document.getElementById('my_Banner').innerHTML = show_B; }

</script>

</html>