p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Javascript How-To (http://p2p.wrox.com/forumdisplay.php?f=87)
-   -   Change Page in iframe (http://p2p.wrox.com/showthread.php?t=25420)

qazi_nomi February 11th, 2005 02:26 AM

Change Page in iframe
 
Hi I have made a page which has the iframe in it and the page which is in iframe has some flash movie and I want to check that if there is no flash player in the system then it will display a diffrent page.

mean simply I check that if there is a flash palyer then iframe display falsh page other wise display different page.

If any one has any idea to solve this problem then I will be appriciate it.

Thanks in advance



(*_*)

Numan
--------------------------------------------------
It is not important what you get But important is how you got it

joefawcett February 11th, 2005 06:32 AM

Well you need some flash detection script, search Google where you will find examples that work on IE and NN et al.
Then you need something like:
Code:

var sFlashUrl = "http://mySite/myFolder/myFlashPage.htm";
var sGetFlashUr; = "http://www.macromedia.com/getFlash.htm"
var oFrame = window.frames["flash"];
if (hasFlash())
{
  oFrame.document.location = sFlashUrl;
}
else
{
  oFrame.document.location = sGetFlashUrl;
}

--

Joe (Microsoft MVP - XML)

qazi_nomi February 11th, 2005 06:59 AM

Dear Joe thanks for your response
But the problem is that how can I check the flash player in the system ?


(*_*)

Numan
--------------------------------------------------
It is not important what you get But important is how you got it

joefawcett February 11th, 2005 07:03 AM

As I said, search for flash detect script on Google, there are dozens.

--

Joe (Microsoft MVP - XML)

qazi_nomi February 11th, 2005 07:16 AM

I got the code from the net which is

var MM_contentVersion = 6;
var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
if ( plugin ) {
        var words = navigator.plugins["Shockwave Flash"].description.split(" ");
        for (var i = 0; i < words.length; ++i)
        {
        if (isNaN(parseInt(words[i])))
        continue;
        var MM_PluginVersion = words[i];
        }
    var MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
}
else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0
   && (navigator.appVersion.indexOf("Win") != -1)) {
    document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n'); //FS hide this from IE4.5 Mac by splitting the tag
    document.write('on error resume next \n');
    document.write('MM_FlashCanPlay = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFla sh." & MM_contentVersion)))\n');
    document.write('</SCR' + 'IPT\> \n');
}
if ( MM_FlashCanPlay ) {
    window.location.replace("http://www.kirupa.com/flash.htm");
} else{
    window.location.replace("http://www.kirupa.com/noflash.htm");
}

(*_*)

Numan
--------------------------------------------------
It is not important what you get But important is how you got it

joefawcett February 11th, 2005 07:42 AM

The author of that script is under the misapprehension that you need VBScript in IE to check for Flash, you don't. You can use:
Code:

function hasFlash(Version)
{
var sVersion = (Version ? "." + Version : "");
try
{
    var oFlash = new ActiveXObject("ShockwaveFlash.ShockwaveFlash" + sVersion);
    oFlash = null;
}
catch(e)
{
    return false;
}
return true;
}

If you pass a version it will test for that version otherwise just for flash in general.

The problem is that it maybe that they have flash but thier security settings either disallow scripting or just disallow object scripting.

--

Joe (Microsoft MVP - XML)

pallone February 14th, 2005 09:07 AM

Hi Joe,

I tried to use the code you provided but I am getting the following error message:

"oFrame.document is null or not an object"

I think the problem is how I am using the iframe tag. I would appreciate if you could have a look at the code below and help to figure out what is wrong.

Cheers,

Claudio

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name=ProgId content=VisualStudio.HTML>
<meta name=Originator content="Microsoft Visual Studio .NET 7.1">

<script type="text/javascript">
<!--

    var sFlashUrl = "http://mySite/myFolder/myFlashPage.htm";
    var sGetFlashUr = "http://www.macromedia.com/getFlash.htm"
    debugger;
    var oFrame = window.frames["flash"];
    if (hasFlash())
    {
        oFrame.document.location = sFlashUrl;
    }
    else
    {
        oFrame.document.location = sGetFlashUrl;
    }

    function hasFlash(Version)
    {
        var sVersion = (Version ? "." + Version : "");
        try
        {
            var oFlash = new ActiveXObject("ShockwaveFlash.ShockwaveFlash" + sVersion);
            oFlash = null;
        }
        catch(e)
        {
            return false;
        }
        return true;
    }

-->
</script>


</head>
<body>
<div>
    <iframe id="flash" src="" width=100% height=50%></iframe>
</div>


</body>
</html>


joefawcett February 14th, 2005 10:08 AM

Sorry, you don't need document, just:
Code:

oFrame.location = ...
or you can do:
Code:

var oFrame = document.getElementById("flash");
oFrame.src = ...


--

Joe (Microsoft MVP - XML)

pallone February 16th, 2005 04:00 PM

Hi Joe,

I have made the changes you suggested but it still doesn't work. I get more or less the same message but without the document:

"oFrame is null or not an object"

I really cannot figure out what is wrong. I am pasting the revised code for you to see what I have changed and would appreciate if you could help to spot what is wrong.

Do you think the way I am building the iframe is right ???? I have not used iframe before and was wondering if there is something wrong with it??

Cheers,

Claudio

<html>
<head>
<title></title>


<script type="text/javascript">
<!--

    var sFlashUrl = "dynamicclasses.aspx";
    var sGetFlashUr = "http://www.macromedia.com/getFlash.htm"
    debugger;
    //var oFrame = window.frames["flash"];
    var oFrame = document.getElementById("flash");
    if (hasFlash())
    {
        oFrame.src = sFlashUrl;
    }
    else
    {
        oFrame.src = sGetFlashUrl;
    }

    function hasFlash(Version)
    {
        var sVersion = (Version ? "." + Version : "");
        try
        {
            var oFlash = new ActiveXObject("ShockwaveFlash.ShockwaveFlash" + sVersion);
            oFlash = null;
        }
        catch(e)
        {
            return false;
        }
        return true;
    }

-->
</script>


</head>
<body>
<div>
    <iframe id="flash" src="" width=100% height=50%></iframe>
</div>


</body>
</html>



joefawcett February 21st, 2005 05:48 AM

Your code runs before the page has finished rendering so the iframe is not available, it needs to be run after the window.onload fires. Put the code into a function called "changeFlashFrame" and add onload="changeFlashFrame();" to the body tag. Don't forget to remove the debugger statement after testing.

--

Joe (Microsoft MVP - XML)


All times are GMT -4. The time now is 04:01 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.