Forum Moderators: open

Message Too Old, No Replies

Detect flash and alternate content

ive made something just need a little advice

         

humpingdan

12:26 pm on Feb 25, 2004 (gmt 0)

10+ Year Member



ok this is what i have so far, it show the flash file if flash is installed - minimum version 4, can redirect if set to true, but as you may have noticed ;) its rather long, what id like to be able to do is slap it in an external .js file and link to it from the html, how can i do this, im not master of javascript, i just dont seem to be able to create a javascript file for all this?

any help is appreciated!

Dan

<SCRIPT LANGUAGE="JavaScript" type="text/javascript">
<!--
var requiredVersion = 4;
var useRedirect = false;
var flashPage = ""
var noFlashPage = ""
var upgradePage = ""
var flash2Installed = false;
var flash3Installed = false;
var flash4Installed = false;
var flash5Installed = false;
var flash6Installed = false;
var maxVersion = 6;
var actualVersion = 0;
var hasRightVersion = false;
var jsVersion = 1.0;
// -->
</SCRIPT>

<SCRIPT LANGUAGE="JavaScript1.1" type="text/javascript">
<!--
var isIE = (navigator.appVersion.indexOf("MSIE")!= -1)? true : false;
var isWin = (navigator.appVersion.indexOf("Windows")!= -1)? true : false;

if(isIE && isWin){
document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
document.write('on error resume next \n');
document.write('flash2Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))) \n');
document.write('flash3Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3"))) \n');
document.write('flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');
document.write('flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');
document.write('flash6Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');
document.write('</SCR' + 'IPT\> \n'); // break up end tag so it doesn't end our script
}
// -->
</SCRIPT>

<SCRIPT LANGUAGE="JavaScript" type="text/javascript">
<!--
function detectFlash() {

if (navigator.plugins) {

if (navigator.plugins["Shockwave Flash 2.0"]
¦¦ navigator.plugins["Shockwave Flash"]) {

var isVersion2 = navigator.plugins["Shockwave Flash 2.0"]? " 2.0" : "";
var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;

var flashVersion = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));

flash2Installed = flashVersion == 2;
flash3Installed = flashVersion == 3;
flash4Installed = flashVersion == 4;
flash5Installed = flashVersion == 5;
flash6Installed = flashVersion >= 6;
}
}
for (var i = 2; i <= maxVersion; i++) {
if (eval("flash" + i + "Installed") == true) actualVersion = i;
}
if(navigator.userAgent.indexOf("WebTV")!= -1) actualVersion = 2;

if (actualVersion >= requiredVersion) {
hasRightVersion = true;

if (useRedirect) {
if(jsVersion > 1.0) {
window.location.replace(flashPage);
} else {
window.location = flashPage;
}
}
} else {
if (useRedirect) {
if(jsVersion > 1.0) {
window.location.replace((actualVersion >= 2)? upgradePage : noFlashPage);
} else {
window.location = (actualVersion >= 2)? upgradePage : noFlashPage;
}
}
}
}
detectFlash();

// -->
</SCRIPT>
</head>

<body>
<SCRIPT LANGUAGE="JavaScript" type="text/javascript">
<!--
if (!useRedirect) {
if(hasRightVersion) {
var oeTags = '<object id="movie" align=""><param name="movie" value="movie.swf"><embed src="movie.swf" quality="high" name="movie" type="application/x-shockwave-flash"></object>';
document.write(oeTags);
} else {
var alternateContent = 'Please upgrade your Flash Plugin'
;
document.write('<img src="image.jpg" width=276 height=110 alt="pic">');
}
}
// -->
</SCRIPT>

Birdman

4:12 pm on Feb 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello,

To link the script externally:

  1. Cut the whole script, including <script> tags out of the head of the doc.
  2. Paste the script to a text editor and strip all <script> tags out.
  3. Save it as filename.js
  4. In the head of the html doc, add: <script type="text/javascript" src="/filename.js"></script>

That's it.