Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Ajax
|
Ajax the combination of XHTML, CSS, DOM, XML, XSLT, XMLHttpRequest, and JavaScript
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Ajax section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 26th, 2007, 03:52 AM
Registered User
 
Join Date: Apr 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problems with [iframe].location

Hi
I'm trying some code with iframes as discussed in the book Ajax.
My code is

<TD id=b2><IFRAME ID="iframe1"></IFRAME><BR>
<INPUT TYPE="BUTTON" OnClick="javascript:document.getElementById('ifram e1').location='http://www.yahoo.it'" VALUE="click"></TD>


this is the syntax provided in the book, but when I click the button nothing happens.

I have to change the code to

<TD id=b2><IFRAME ID="iframe1"></IFRAME><BR>
<INPUT TYPE="BUTTON" OnClick="javascript:document.getElementById('ifram e1').src='http://www.yahoo.it'" VALUE="click"></TD>


and now when I click the button the content of the iframe changes.

Can someone explain me why I can't use the syntax I read in the book?
Thanks to everyone

 
Old April 26th, 2007, 04:49 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I think it's just a mistake in the book. The iframe doesn't have a location property, the window it contains does. What page, and in which edition, was that?

--

Joe (Microsoft MVP - XML)
 
Old April 26th, 2007, 05:19 AM
Registered User
 
Join Date: Apr 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Maybe it's my mistake...I read again the example code and I modify my testing page. Now the code is

<TD id=b2><IFRAME ID="iframe1"></IFRAME><BR>
<INPUT TYPE="BUTTON" OnClick="javascript:frames['iframe1'].location='http://www.yahoo.it'" VALUE="click"></TD>


I thought (wrong?) frames['iframe1'] and document.getElementById['iframe1'] return the same object.

Now the source code works on IE and Opera but not with Firefox, the error console reports "Error: frames.iframe1 has no propriertis"
 
Old April 26th, 2007, 05:51 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Yes getElementById() will fetch the frame element which is different from the frame and its contents, retrieved via the frames collection. I have been caught out by that myself before now. Not sure why Firefox fails, I will try to test later today. I think you actually need to use the name attribute rather than the id though.

--

Joe (Microsoft MVP - XML)
 
Old April 26th, 2007, 07:42 AM
Registered User
 
Join Date: Apr 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, I specified NAME attribute too and then firefox works.
final code is

<TD id=b2><IFRAME ID="iframe1" name="iframe1"></IFRAME><BR>
<INPUT TYPE="BUTTON" OnClick="javascript:top.frames['iframe1'].location='http://www.yahoo.it'" VALUE="click"></TD>


thanks for support :)






Similar Threads
Thread Thread Starter Forum Replies Last Post
values from one iframe to another iframe URGENT raaj Beginning PHP 2 February 27th, 2007 12:19 PM
Another one of those iframe(?) problems Anthem HTML Code Clinic 0 August 9th, 2006 11:42 AM
Problems with loading external pics into an IFrame nancy Classic ASP Databases 2 April 26th, 2005 10:33 AM
iframe rockon HTML Code Clinic 1 March 2nd, 2005 06:00 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.