Wrox Programmer Forums
|
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 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 October 30th, 2003, 10:28 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 347
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Adam H-W
Default i frames and images

I'm wanting to use i frames for this particular project I'm on at the moment. What I want to do is pull an image into the iframe depending on what link is clicked. This is what I'm attempting to use:

<script language="javascript" type="text/javascript">
<!-- Hide script from older browsers

pageCount = new Array(0,0,0,0)

function writeContent(thisPage) {
pageCount[thisPage]++

content.document.write("<html><head><\/head><body bgcolor='#FFFFFF'><h1>")
content.document.write("You are now looking at page " + thisPage + ".<br/>")
content.document.write("<\/h1><\/body><\/html>")
content.document.close()
}
// end hiding script-->
</script>

However, instead of wanting to see 'You are now looking at page 1' for example, I want to be able to view an image dependent on what link is clicked.

Can anyone tell me how I could go about this. (As you might have guessed, I don't know a great deal about javascript!)

thanks

Adam
 
Old October 30th, 2003, 10:43 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

You cannot document.write into a page that has finished loading. Something like this should work, in your page:
Code:
<iframe id="fraImage" src="default.gif"></frame>
in a script block in the main page:
Code:
function changeImage(Frame, Path)
{
  var fra = document.getElementById(Frame);
  fra.src = Path;
}
and in the link:
Code:
<a href="/" onclick="changeImage('fraImage', 'pathToImage.gif');return false;">View image one.</a>


--

Joe
 
Old October 30th, 2003, 11:00 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Actually you may not need any JavaScript for this. Give the iframe a name and have a standard link with the target attribute set to the name of your iframe and the href set to point at your image.

--

Joe
 
Old October 30th, 2003, 11:38 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 347
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Adam H-W
Default

Great, thanks again Joe.
 
Old October 31st, 2003, 11:09 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 347
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Adam H-W
Default

Hi Joe,

sorry, just one more thing - does an iframe have CSS attributes?

thanks

Adam
 
Old October 31st, 2003, 11:12 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

http://msdn.microsoft.com/library/de...asp?frame=true

Drill down to objects|iframe


--

Joe





Similar Threads
Thread Thread Starter Forum Replies Last Post
Load Images from and Save Images to a Database cyndie VB.NET 2 August 17th, 2008 06:42 AM
Frames ricardo_s HTML Code Clinic 1 April 27th, 2006 02:37 PM
frames twinkle Javascript How-To 34 March 31st, 2004 06:06 AM
i frames and all that Adam H-W HTML Code Clinic 2 November 5th, 2003 12:24 PM





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