Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 11th, 2005, 02:26 AM
Friend of Wrox
Points: 1,288, Level: 14
Points: 1,288, Level: 14 Points: 1,288, Level: 14 Points: 1,288, Level: 14
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2004
Location: Stockholm, Sweden
Posts: 331
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to qazi_nomi
Default 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
__________________
(*_*)

Numan
--------------------------------------------------
It is not important what you get But important is  how you got it
Reply With Quote
  #2 (permalink)  
Old February 11th, 2005, 06:32 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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)
Reply With Quote
  #3 (permalink)  
Old February 11th, 2005, 06:59 AM
Friend of Wrox
Points: 1,288, Level: 14
Points: 1,288, Level: 14 Points: 1,288, Level: 14 Points: 1,288, Level: 14
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2004
Location: Stockholm, Sweden
Posts: 331
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to qazi_nomi
Default

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
Reply With Quote
  #4 (permalink)  
Old February 11th, 2005, 07:03 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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

--

Joe (Microsoft MVP - XML)
Reply With Quote
  #5 (permalink)  
Old February 11th, 2005, 07:16 AM
Friend of Wrox
Points: 1,288, Level: 14
Points: 1,288, Level: 14 Points: 1,288, Level: 14 Points: 1,288, Level: 14
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2004
Location: Stockholm, Sweden
Posts: 331
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to qazi_nomi
Default

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
Reply With Quote
  #6 (permalink)  
Old February 11th, 2005, 07:42 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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)
Reply With Quote
  #7 (permalink)  
Old February 14th, 2005, 09:07 AM
Friend of Wrox
Points: 1,243, Level: 13
Points: 1,243, Level: 13 Points: 1,243, Level: 13 Points: 1,243, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2003
Location: , , United Kingdom.
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default

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>

Reply With Quote
  #8 (permalink)  
Old February 14th, 2005, 10:08 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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)
Reply With Quote
  #9 (permalink)  
Old February 16th, 2005, 04:00 PM
Friend of Wrox
Points: 1,243, Level: 13
Points: 1,243, Level: 13 Points: 1,243, Level: 13 Points: 1,243, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2003
Location: , , United Kingdom.
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default

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>


Reply With Quote
  #10 (permalink)  
Old February 21st, 2005, 05:48 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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)
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBScript to change target of Iframe dartcoach BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 May 9th, 2008 11:45 AM
Problem with iframe content when refreshing page klax Javascript 0 April 21st, 2007 04:43 PM
how to prevent page jumping while click on iframe' kathirnk HTML Code Clinic 0 April 16th, 2007 06:39 AM
targeting external page in another page's IFRAME nancy HTML Code Clinic 1 March 30th, 2006 03:22 PM
Accessing page object within an IFRAME drettberg ASP.NET 1.0 and 1.1 Professional 3 September 22nd, 2003 11:49 AM



All times are GMT -4. The time now is 11:50 PM.


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