Javascript and iframe question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • S'fly

    Javascript and iframe question

    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="javas cript">
    <!--- begin
    var nifty_little_wi ndow = null;
    function gateKeeper() {
    nifty_little_wi ndow = window.open('ga tekeep.html','t heKeeper',
    'width=410,heig ht=300,resizabl e=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.h tml" is this:

    <script language="JavaS cript">
    <!-- Begin
    function goForit() {
    var location;
    var password;
    password=this.d ocument.testfor m.inputbox.valu e
    location=passwo rd + ".html"
    fetch(location)
    theKeeper=windo w.close()
    }
    function fetch(location) {
    var root;
    if (opener.closed) {
    root=window.ope n
    ('','theKeepers Gopher','toolba r=yes,location= yes,status=yes, menubar=yes,
    scrollbars=yes, resizable=yes,c opyhistory=no') ;
    root.location.h ref = 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="MyIfram e">click</a> or something and
    modify only the second script? Help please. :)

    TIA

    --
    S'fly
  • Thomas 'PointedEars' Lahn

    #2
    Re: Javascript and iframe question

    S'fly wrote:
    [color=blue]
    > <script language="javas cript">[/color]

    The `type' attribute is missing for valid HTML 4 and the `language'
    attribute is deprecated.
    [color=blue]
    > <!--- begin[/color]

    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.
    [color=blue]
    > [...]
    > // end --->[/color]

    See above. (The `//' is required only for the script engine not to
    interpret `--' as decrement operator, not for ending the SGML comment.)
    [color=blue]
    > </script>
    >
    > So this one opens a popup of course.[/color]

    Of course not ;-)
    [color=blue]
    > How to change this so it will open inside an iframe?[/color]

    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

    Comment

    • Jim Ley

      #3
      Re: Javascript and iframe question

      On Sun, 09 Nov 2003 20:18:54 +0100, Thomas 'PointedEars' Lahn
      <PointedEars@we b.de> wrote:
      [color=blue]
      >S'fly wrote:
      >[color=green]
      >> <script language="javas cript">[/color]
      >
      >The `type' attribute is missing for valid HTML 4 and the `language'
      >attribute is deprecated.[/color]

      The OP doesn't specify a doctype, so you do not know which version of
      HTML or XHTML he may be using.
      [color=blue][color=green]
      >> <!--- begin[/color]
      >
      >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,[/color]

      Gibberish - could you cite this agreement?
      [color=blue]
      > you use `<!' (the MDO -- Markup Declaration Open) here.[/color]

      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.
      [color=blue]
      > AFAIK only b0rken IE will
      >execute scripts despite of invalid SGML syntax.[/color]

      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.
      --
      comp.lang.javas cript FAQ - http://jibbering.com/faq/

      Comment

      • Thomas 'PointedEars' Lahn

        #4
        Re: Javascript and iframe question

        Jim Ley wrote:
        [color=blue]
        > [...] Thomas 'PointedEars' Lahn <PointedEars@we b.de> wrote:[color=green]
        >>S'fly wrote:
        >>[color=darkred]
        >>> <script language="javas cript">[/color]
        >>
        >>The `type' attribute is missing for valid HTML 4 and the `language'
        >>attribute is deprecated.[/color]
        >
        > The OP doesn't specify a doctype, so you do not know which version of
        > HTML or XHTML he may be using.[/color]

        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.
        [color=blue][color=green][color=darkred]
        >>> <!--- begin[/color]
        >>
        >>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,[/color]
        >
        > Gibberish - could you cite this agreement?[/color]


        [color=blue]
        > However 3 -, would not be invalid in any case (test if you're not sure.[/color]

        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.
        [color=blue][color=green]
        >> AFAIK only b0rken IE will execute scripts despite of invalid SGML syntax.[/color]
        >
        > There's nothing invalid in the OP's snippet.[/color]

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


        PointedEars

        Comment

        • Jim Ley

          #5
          Re: Javascript and iframe question

          On Sun, 09 Nov 2003 21:51:42 +0100, Thomas 'PointedEars' Lahn
          <PointedEars@we b.de> wrote:
          [color=blue]
          >If he doesn't specify the DOCTYPE, I assume what a recent UA using a tagsoup
          >parser will assume: HTML 4.01 Transitional.[/color]

          Could you cite an example of any UA which does that, I understood all
          UA's just assume tag-soup, as RFC 2854 indicates.
          [color=blue][color=green]
          >> Gibberish - could you cite this agreement?[/color]
          >
          >http://www.w3.org/TR/html4/interact/...idx-user_agent[/color]

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

          The example at the content in a SCRIPT element, that is where it would
          not be invalid... This is a strawman example.
          [color=blue]
          >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.[/color]

          <!-- will "begin the comment" and - will part of the comment.
          [color=blue]
          >IBTD. Feed that code to the validator and see for yourself.[/color]

          <URL:
          http://validator.w3.org/check?uri=ht...ne=1&verbose=1[color=blue]
          >[/color]

          Which is an HTML 4.01 strict page containing:

          <script type="text/javascript">
          <!--- begin
          var nifty_little_wi ndow = null;
          function gateKeeper() {
          nifty_little_wi ndow = window.open('ga tekeep.html','t heKeeper',
          'width=410,heig ht=300,resizabl e=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.
          --
          comp.lang.javas cript FAQ - http://jibbering.com/faq/

          Comment

          • Thomas 'PointedEars' Lahn

            #6
            Re: Javascript and iframe question

            Jim Ley wrote:
            [color=blue]
            > [...] Thomas 'PointedEars' Lahn [...] wrote:[color=green][color=darkred]
            >>> Gibberish - could you cite this agreement?[/color]
            >>
            >>http://www.w3.org/TR/html4/interact/...idx-user_agent[/color]
            >
            > Doesn't mention anything about the agreement, just illustrates that
            > some script languages provide such a mechanism, as JS does.[/color]

            | 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.
            [color=blue][color=green]
            >>| <body>
            >>| <!---[/color]
            >
            > The example at the content in a SCRIPT element, that is where it would
            > not be invalid... This is a strawman example.[/color]

            At least it proves that /<!---[^-]*--->/ is not a valid SGML declaration
            and comment.
            [color=blue][color=green]
            >>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.[/color]
            >
            > <!-- will "begin the comment" and - will part of the comment.[/color]

            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.
            [color=blue][color=green]
            >>IBTD. Feed that code to the validator and see for yourself.[/color]
            >
            > <URL:
            > http://validator.w3.org/check?uri=ht...ne=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.[/color]

            Full ACK.


            PointedEars

            Comment

            • Thomas 'PointedEars' Lahn

              #7
              Re: Javascript and iframe question

              Jim Ley wrote:
              [color=blue]
              > [...] Thomas 'PointedEars' Lahn [...] wrote:[color=green]
              >> Jim Ley wrote:[color=darkred]
              >>> The example at the content in a SCRIPT element, that is where it would
              >>> not be invalid... This is a strawman example.[/color]
              >>
              >> At least it proves that /<!---[^-]*--->/ is not a valid SGML declaration
              >> and comment.[/color]
              >
              > Something, no-one had ever argued with, hence it was a strawman.[/color]

              Name it as you like, it proves that
              [color=blue][color=green][color=darkred]
              >>> <!-- will "begin the comment" and - will part of the comment.[/color][/color][/color]

              is definitely wrong.
              [color=blue][color=green]
              >>You're wrong, as I have already proven. `<!---' is an ambiguous SGML
              >>declaration and therefore not allowed (in parsed content.)[/color]
              >
              > Comments are not allowed inside SCRIPT, they're just CDATA in
              > HTML4.01,[/color]

              They *are* allowed as CDATA but not parsed because the content model.
              [color=blue][color=green]
              >>(FYI: I am currently transforming the online version of a Math resource
              >>book from HTML (with images) to XHTML (with MathML).[/color]
              >
              > 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.[/color]

              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.)
              [color=blue][color=green]
              >>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.[/color]
              >
              > Right, so why did you correct the OP on this?[/color]

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


              EOD

              PointedEars

              Comment

              Working...