Javascript and iframe question

S

S'fly

Hi,

I'm struggling with the famous "gatekeeper" a little. Normally, it opens
in a popup window, and from there it goes on. But I like this script to
open in an iframe, and not in a popup. It opens with a link.

This is in the main page (where also the iframe):

<script language="javascript">
<!--- begin
var nifty_little_window = null;
function gateKeeper() {
nifty_little_window = window.open('gatekeep.html','theKeeper',
'width=410,height=300,resizable=0,left=0,top=0')
}
// end --->
</script>

So this one opens a popup of course. How to change this so it will open
inside an iframe?

The "gatekeep.html" is this:

<script language="JavaScript">
<!-- Begin
function goForit() {
var location;
var password;
password=this.document.testform.inputbox.value
location=password + ".html"
fetch(location)
theKeeper=window.close()
}
function fetch(location) {
var root;
if (opener.closed) {
root=window.open
('','theKeepersGopher','toolbar=yes,location=yes,status=yes,menubar=yes,
scrollbars=yes,resizable=yes,copyhistory=no');
root.location.href = location;
} else {
opener.location.href = location;
}
}
// End hiding -->
</script>


Is there any way to point the first script to an iframe? It's driving me
nuts! Or should I directly point the second script to the iframe, like
<a href="gatekeep.html" target="MyIframe">click</a> or something and
modify only the second script? Help please. :)

TIA
 
T

Thomas 'PointedEars' Lahn

S'fly said:
<script language="javascript">

The `type' attribute is missing for valid HTML 4 and the `language'
attribute is deprecated.
<!--- begin

SGML comments begin and end with `--'. Because they are allowed in SGML
context only and because of an agreement that a JavaScript engine should
ignore the first non-blank line when begins with a SGML comment, you use
`<!' (the MDO -- Markup Declaration Open) here. AFAIK only b0rken IE will
execute scripts despite of invalid SGML syntax.
[...]
// end --->

See above. (The `//' is required only for the script engine not to
interpret `--' as decrement operator, not for ending the SGML comment.)
</script>

So this one opens a popup of course.

Of course not ;-)
How to change this so it will open inside an iframe?

An iFrame is part of the frames[...] collection of Window objects. So the
easy and most compatible way is to name the iFrame by using the respective
attribute and access it via this collection:

window.frames['foobar'].location = "gatekeep.html";

You may need to replace `window' by a reference to a Window object that
contains the iFrame.


PointedEars
 
J

Jim Ley

The `type' attribute is missing for valid HTML 4 and the `language'
attribute is deprecated.

The OP doesn't specify a doctype, so you do not know which version of
HTML or XHTML he may be using.
SGML comments begin and end with `--'. Because they are allowed in SGML
context only and because of an agreement that a JavaScript engine should
ignore the first non-blank line when begins with a SGML comment,

Gibberish - could you cite this agreement?
you use `<!' (the MDO -- Markup Declaration Open) here.

All completely irrelevant as the content-type of SCRIPT is CDATA,
comments are not allowed (well they're not comments, they're just
CDATA) However 3 -, would not be invalid in any case (test if you're
not sure.
AFAIK only b0rken IE will
execute scripts despite of invalid SGML syntax.

There's nothing invalid in the OP's snippet. (or if you assume HTML
4.01 strict then the lack of type existance of language was.)

Jim.
 
T

Thomas 'PointedEars' Lahn

Jim said:
[...] Thomas 'PointedEars' Lahn said:
S'fly said:
<script language="javascript">

The `type' attribute is missing for valid HTML 4 and the `language'
attribute is deprecated.

The OP doesn't specify a doctype, so you do not know which version of
HTML or XHTML he may be using.

If he doesn't specify the DOCTYPE, I assume what a recent UA using a tagsoup
parser will assume: HTML 4.01 Transitional. That's quite generous since a
strict SGML parser will stop(!) when it fails to find a valid DOCTYPE
declaration. The W3C Validator uses the latte parser and you see the result.
Gibberish - could you cite this agreement?
http://www.w3.org/TR/html4/interact/scripts.html#idx-user_agent

However 3 -, would not be invalid in any case (test if you're not sure.

Input source:

| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
| "http://www.w3.org/TR/html4/loose.dtd">
| [...]
| <body>
| <!---
|
| asfasf
|
| --->

Output of http://validator.w3.org/check (default options)

| This page is not Valid HTML 4.01 Transitional!
|
| Below are the results of attempting to parse this document with an SGML
parser.
|
| 1. Line 55, column 6: invalid comment declaration
|
| --->
| ^
|
| 2. Line 51, column 4: comment declaration started here (explain...).
|
| <!---
| ^
|

The same goes for HTML 2.0 (obsolete) and HTML 3.2, if I let the Validator
ignore my DOCTYPE declaration.

If you think about it, it must be invalid, since if you consider the
second `--' of `<!---' as start of the comment, `<!-' is not a valid
SGML declaration.
There's nothing invalid in the OP's snippet.

IBTD. Feed that code to the validator and see for yourself.


PointedEars
 
J

Jim Ley

If he doesn't specify the DOCTYPE, I assume what a recent UA using a tagsoup
parser will assume: HTML 4.01 Transitional.

Could you cite an example of any UA which does that, I understood all
UA's just assume tag-soup, as RFC 2854 indicates.

Doesn't mention anything about the agreement, just illustrates that
some script languages provide such a mechanism, as JS does.
| <body>
| <!---

The example at the content in a SCRIPT element, that is where it would
not be invalid... This is a strawman example.
If you think about it, it must be invalid, since if you consider the
second `--' of `<!---' as start of the comment, `<!-' is not a valid
SGML declaration.

<!-- will "begin the comment" and - will part of the comment.
IBTD. Feed that code to the validator and see for yourself.
<URL:
http://validator.w3.org/check?uri=h...&doctype=Inline&ss=1&sp=1&outline=1&verbose=1

Which is an HTML 4.01 strict page containing:

<script type="text/javascript">
<!--- begin
var nifty_little_window = null;
function gateKeeper() {
nifty_little_window = window.open('gatekeep.html','theKeeper',
'width=410,height=300,resizable=0,left=0,top=0')
}
// end --->
</script>

which is a slightly modified example from the OP - it is valid HTML,
the <!--- and ---> do not denote SGML comments inside of a script
element.

Jim.
 
T

Thomas 'PointedEars' Lahn

Jim said:
Doesn't mention anything about the agreement, just illustrates that
some script languages provide such a mechanism, as JS does.

| User agents that don't recognize the SCRIPT element will thus ignore
| the comment while smart scripting engines will understand that the
| script in comments should be executed.

I read this as an agreement since it is part of a specification where
producers of well-known UAs have worked on and their UAs actually obey
what has been specified there.
The example at the content in a SCRIPT element, that is where it would
not be invalid... This is a strawman example.


<!-- will "begin the comment" and - will part of the comment.

You're wrong, as I have already proven. `<!---' is an ambiguous SGML
declaration and therefore not allowed (in parsed content.) Since `--'
opens and closes the comment, adjacent `-'s within comments must occur
in factors of four, or in pairs of two, separated by whitespace or valid
keywords, for valid declarations. Thus /<!>/ is a valid (empty)
declaration, and /<!\w*(\s*--[^-]?.*[^-]?--\s*)+\w*>/ are valid declarations
with comments, provided that /\w/ is a character of a valid keyword.

(FYI: I am currently transforming the online version of a Math resource
book from HTML (with images) to XHTML (with MathML). The author of the
HTML version did not follow the specification in this point which is why
Mozilla/5.0, in contrast to IE, shows a blank page for HTML documents
containing invalid comments, using them as horizontal rules in the source code.)

But as you have stated before correctly, the content *model* (not type)
of the `script' element is CDATA which is not parsed. So `<!---' is not
invalid here. However, a script engine must understand such non-script
character data to parse the script code correctly, and if comes to that,
I rather stick to what has been specified and call the other versions not
recommended.
IBTD. Feed that code to the validator and see for yourself.

<URL:
http://validator.w3.org/check?uri=h...&doctype=Inline&ss=1&sp=1&outline=1&verbose=1
[...]
which is a slightly modified example from the OP - it is valid HTML,
the <!--- and ---> do not denote SGML comments inside of a script
element.

Full ACK.


PointedEars
 
J

Jim Ley

Jim said:
The example at the content in a SCRIPT element, that is where it would
not be invalid... This is a strawman example.

At least it proves that /<!---[^-]*--->/ is not a valid SGML declaration
and comment.

Something, no-one had ever argued with, hence it was a strawman.
You're wrong, as I have already proven. `<!---' is an ambiguous SGML
declaration and therefore not allowed (in parsed content.)

Comments are not allowed inside SCRIPT, they're just CDATA in
HTML4.01, they are not comments <!-- or any other combinations of
characters are perfectly legal, hence your original complaint to the
OP was wrong, he's allowed to do whatever he wants.
(FYI: I am currently transforming the online version of a Math resource
book from HTML (with images) to XHTML (with MathML).

Good for you, application/xhtml+xml is a good technology, one that is
very rarely discussed here, as we all live in the text/html real
world.
But as you have stated before correctly, the content *model* (not type)
of the `script' element is CDATA which is not parsed. So `<!---' is not
invalid here.

Right, so why did you correct the OP on this? My problem is that
this sort of pedantry (anti comments in script) which do no harm can
confuse the user. Especially if you actually confuse the issue -
saying they do no good, and could be dangerous in XHTML - don't put
them in. Is fine, but probably unnecessarily confusing, but saying
they're wrong and only invalid UA's would execute the script is just
mis-information.

Jim.
 
T

Thomas 'PointedEars' Lahn

Jim said:
Jim said:
The example at the content in a SCRIPT element, that is where it would
not be invalid... This is a strawman example.

At least it proves that /<!---[^-]*--->/ is not a valid SGML declaration
and comment.

Something, no-one had ever argued with, hence it was a strawman.

Name it as you like, it proves that

is definitely wrong.
Comments are not allowed inside SCRIPT, they're just CDATA in
HTML4.01,

They *are* allowed as CDATA but not parsed because the content model.
Good for you, application/xhtml+xml is a good technology, one that is
very rarely discussed here, as we all live in the text/html real
world.

Obviously you have no clue about MathML which is a valid argument
for using XHTML (otherwise I would not have started to transform
the HTML in the first place.)
Right, so why did you correct the OP on this?

Because I was not aware of the CDATA content model.
Thanks for pointing this out to me.


EOD

PointedEars
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top