newbie: about iframe and id + name

J

Jeff

I have this code my index file:

<IFRAME src="main.html" width="550" height="100%" id="main" name="main"
height="auto"
scrolling="no" frameborder="1">
</IFRAME>

***************************************************************
I have this code in a html-page opened in a iframe in index: (demo.html)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Test</title>
<script type="text/javascript" language="JavaScript">

function testFunc(href) {
frames['main'].location.href = 'href';
}

</script>
</head>

<BODY BGColor="white">
<a href="javascript:testFunc('debug.html')">Test of iframe</A>
</BODY>
</html>


The index file can open through javascript html-pages and put them in
iframes defined in the index-page

My problem is that testFunc doesn't open the debug.html page....
Can the reason for this be that the iframe is defined in the index file and
demo.html doesn't know about them?

Jeff
 
J

Jeff

Thanks for the tip about that double height thing

found a solution for my problem:

function testFunc(href) {
parent.frames['main'].location.href = 'href'; //I added parent and it
works fine
}
 
D

Dylan Parry

Jeff said:
I have this code my index file:

<IFRAME src="main.html" width="550" height="100%" id="main" name="main"
height="auto"
scrolling="no" frameborder="1">
</IFRAME>

You sure you want two height attributes in that element?
I have this code in a html-page opened in a iframe in index: (demo.html)
<snip code />

Surely, if the link is within the iframe and you want the content to load
in that iframe you only need a regular link? ie. the iframe contains <a
href="debug.html">Test of iframe</a>.

Or are you trying to do something else?
 
S

Steve Pugh

Jeff said:
function testFunc(href) {
frames['main'].location.href = 'href';
}

Why is the href quoted on the right hand side? It's a variable not a
string, and so should not be quoted. I would in general avoid giving
variables names that are the same as existing objects or properties.

Steve
 
J

Jeff

I'm sorry. of course it'll be without qoutes. My mistake when I typed in the
code in the post
But anyway, my problem is solved


Steve Pugh said:
Jeff said:
function testFunc(href) {
frames['main'].location.href = 'href';
}

Why is the href quoted on the right hand side? It's a variable not a
string, and so should not be quoted. I would in general avoid giving
variables names that are the same as existing objects or properties.

Steve
--
"My theories appal you, my heresies outrage you,
I never answer letters and you don't like my tie." - The Doctor

Steve Pugh <[email protected]> <http://steve.pugh.net/>
 
E

Eric Bohlman

I'm sorry. of course it'll be without qoutes. My mistake when I typed
in the code in the post
But anyway, my problem is solved

Veterans of programming-language newsgroups (and the same logic applies to
HTML and CSS) have learned to always, yes always, copy-and-paste code that
they're presenting for debugging rather than retyping it. As you've seen,
code almost invariably mutates when retyped. Since computers are so bloody
literal-minded, code that's "almost like" the original code will usually
give results that are "completely unlike" the original code.

Oh, and due to "psychological set" it often happens that you get the exact
opposite of what happened here: your real code contains a typo or other
low-level mistake that's causing your problem, but you end up retyping what
you meant to write in the first place rather than what you really did write
(the correction happens at a subconscious level). Then everybody winds up
scratching their heads and saying "that works fine for me."

Of course for longer chunks of code, it's best to simply post a URL to the
original. If the original isn't publicly accessible for some good reason,
then strip it down to create a test case that doesn't contain any
proprietary information or what have you. Often the very process of
creating such a test case will make the cause of the problem apparent to
you right away, in which case you'll have saved everybody's time, including
your own.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top