Dynamic include files

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Adam

    Dynamic include files

    Hi All,

    Is it possible to use includes dynamically in html.

    Hopefully the following example will give an idea what I am rying to do.

    Thanks in advance
    Adam

    <script language="javas cript">
    function checkFileToIncl ude(){
    if (location.searc h == "?file1"){
    return "<!--#include file='file1.htm l'-->"
    }else{
    return "<!--#include file='file2.htm l'-->"
    }
    }
    </script>

    <html>
    ..
    ..
    <a href="www.mydom ain.com/test?file1">Inc lude File 1</a>
    <a href="www.mydom ain.com/test?file2">Inc lude File 2</a>
    ..
    ..
    <td>
    document.write( checkFileToIncl ude())
    </td>

    ..
    ..
    ..
    </html>
  • Guido Wesdorp

    #2
    Re: Dynamic include files

    Adam wrote:[color=blue]
    > Hi All,
    >
    > Is it possible to use includes dynamically in html.
    >[/color]
    ....
    [color=blue]
    > <script language="javas cript">
    > function checkFileToIncl ude(){
    > if (location.searc h == "?file1"){
    > return "<!--#include file='file1.htm l'-->"
    > }else{
    > return "<!--#include file='file2.htm l'-->"
    > }
    > }
    > </script>
    >[/color]

    Lol not unless this script runs on the server... I assume you want to
    perform the actions in the #include statements, and those should be
    performed on the server side, since the JavaScript is executed on the
    client side the server will never know what process.
    The funny thing is that this may actually work, but then the other way
    round from what you seem to expect: the server will, *before* sending
    the result to the client, replace the SSI instructions with the content
    of *both* html files and later on the JavaScript picks one of those to
    use...

    Cheers,

    Guido

    Comment

    • kaeli

      #3
      Re: Dynamic include files

      In article <a84b035a.04052 70445.21c14a8d@ posting.google. com>,
      areynoldsx@hotm ail.com enlightened us with...[color=blue]
      > Hi All,
      >
      > Is it possible to use includes dynamically in html.
      >[/color]

      Yes, but not with javascript, which runs on the client. SSI runs on the
      server.
      You're using SSI for the includes - use SSI for the whole thing. You can
      use it to check a querystring param and conditionally include content.



      --
      --
      ~kaeli~
      User: The word computer professionals use when they mean
      'idiot'.



      Comment

      • Ron

        #4
        Re: Dynamic include files

        Adam wrote:
        [color=blue]
        >Hi All,
        >
        >Is it possible to use includes dynamically in html.
        >
        >Hopefully the following example will give an idea what I am rying to do.
        >
        >Thanks in advance
        >Adam
        >
        ><script language="javas cript">
        >function checkFileToIncl ude(){
        > if (location.searc h == "?file1"){
        > return "<!--#include file='file1.htm l'-->"
        > }else{
        > return "<!--#include file='file2.htm l'-->"
        > }
        >}
        ></script>
        >
        ><html>
        >.
        >.
        ><a href="www.mydom ain.com/test?file1">Inc lude File 1</a>
        ><a href="www.mydom ain.com/test?file2">Inc lude File 2</a>
        >.
        >.
        ><td>
        > document.write( checkFileToIncl ude())
        ></td>
        >
        >.
        >.
        >.
        ></html>
        >
        >[/color]
        In addition to the two replies, you can also try using object elements
        instead of server-side includes, which allows you to treat the content
        of an object like an inline frame. Ie.,
        <object id="file1" data="file1.htm l" type="text/html" width="100%"
        standby="Loadin g file1.html...">
        Your browser cannot render embedded HTML documents.
        </object>
        The difference is that your file1.html document should be a valid HTML
        document, not just an HTML fragment. You can access that document
        through the object's contentDocument property. I've used this method to
        include sitewide menus on my websites.

        Comment

        • kaeli

          #5
          Re: Dynamic include files

          In article <s5stc.59999$cz 5.24777812@news 4.srv.hcvlny.cv .net>,
          webmaster@slide r142.donttypeth is.com enlightened us with...[color=blue]
          > <object id="file1" data="file1.htm l" type="text/html" width="100%"
          > standby="Loadin g file1.html...">
          > Your browser cannot render embedded HTML documents.
          > </object>[/color]

          I really like this method. This is the first time I've seen it for html
          pages. Unfortunately, IE doesn't seem to support it.

          Does anyone know what browsers do support this?
          I tested Opera 7 and Netscape 7 and they were fine. IE 6, however,
          didn't render anything at all, even the warning that it isn't supported.
          Anyone test with Safari, Konqueror, etc? I assume Netscape 4 would not
          support it.

          I used the following doctype for both html files:
          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
          "http://www.w3.org/TR/REC-html40/loose.dtd">

          Should I use a different one for this?

          --
          --
          ~kaeli~
          Dijon vu - the same mustard as before.



          Comment

          • Ron

            #6
            Re: Dynamic include files

            kaeli wrote:
            [color=blue]
            >In article <s5stc.59999$cz 5.24777812@news 4.srv.hcvlny.cv .net>,
            >webmaster@slid er142.donttypet his.com enlightened us with...
            >
            >[color=green]
            >><object id="file1" data="file1.htm l" type="text/html" width="100%"
            >>standby="Load ing file1.html...">
            >>Your browser cannot render embedded HTML documents.
            >></object>
            >>
            >>[/color]
            >
            >I really like this method. This is the first time I've seen it for html
            >pages. Unfortunately, IE doesn't seem to support it.
            >
            >Does anyone know what browsers do support this?
            >I tested Opera 7 and Netscape 7 and they were fine. IE 6, however,
            >didn't render anything at all, even the warning that it isn't supported.
            >Anyone test with Safari, Konqueror, etc? I assume Netscape 4 would not
            >support it.
            >
            >I used the following doctype for both html files:
            ><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
            >"http://www.w3.org/TR/REC-html40/loose.dtd">
            >
            >Should I use a different one for this?
            >
            >
            >[/color]
            Heya kaeli,
            I normally use the XHTML 1.1 standard with basic support for older
            browsers, but it works in IE6 as well, at least if the document you're
            calling is HTML. See the following two example pages in any browser:
            http://slider142.com/xhtml/objecttest.xhtml - The base document is XHTML 1.1
            http://slider142.com/xhtml/objecttest.html - The base document is HTML
            4.01 Strict

            Comment

            • kaeli

              #7
              Re: Dynamic include files

              In article <sEJtc.67181$cz 5.27935725@news 4.srv.hcvlny.cv .net>,
              webmaster@slide r142.donttypeth is.com enlightened us with...[color=blue][color=green]
              > >
              > >[/color]
              > Heya kaeli,
              > I normally use the XHTML 1.1 standard with basic support for older
              > browsers, but it works in IE6 as well, at least if the document you're
              > calling is HTML. See the following two example pages in any browser:
              > http://slider142.com/xhtml/objecttest.xhtml - The base document is XHTML 1.1
              > http://slider142.com/xhtml/objecttest.html - The base document is HTML
              > 4.01 Strict
              >[/color]

              You know, when I went to your link, it worked fine, but when I tried it
              locally with my file, it didn't work (IE file->open).

              I realized I left something out - the height attribute. Apparently IE
              needs that more than Netscape and Opera do, as it was shrinking it to 0
              px. :)
              Your original example didn't have the height specified. Your code on
              this link has it.

              Thanks!

              --
              --
              ~kaeli~
              Who is General Failure and why is he reading my hard disk?



              Comment

              • Jim Ley

                #8
                Re: Dynamic include files

                On Fri, 28 May 2004 16:19:36 GMT, Ron
                <webmaster@slid er142.donttypet his.com> wrote:
                [color=blue]
                >Heya kaeli,
                >I normally use the XHTML 1.1 standard with basic support for older
                >browsers, but it works in IE6 as well,[/color]

                no it does not, IE does not render XHTML 1.1. (other than as an XML
                tree)
                [color=blue]
                > at least if the document you're
                >calling is HTML. See the following two example pages in any browser:
                >http://slider142.com/xhtml/objecttest.xhtml - The base document is XHTML 1.1
                >http://slider142.com/xhtml/objecttest.html - The base document is HTML
                >4.01 Strict[/color]

                Use IFRAME.

                Jim.
                --
                comp.lang.javas cript FAQ - http://jibbering.com/faq/

                Comment

                • Ron

                  #9
                  Re: Dynamic include files

                  Jim Ley wrote:
                  [color=blue]
                  >On Fri, 28 May 2004 16:19:36 GMT, Ron
                  ><webmaster@sli der142.donttype this.com> wrote:
                  >
                  >
                  >[color=green]
                  >>Heya kaeli,
                  >>I normally use the XHTML 1.1 standard with basic support for older
                  >>browsers, but it works in IE6 as well,
                  >>
                  >>[/color]
                  >
                  >no it does not, IE does not render XHTML 1.1. (other than as an XML
                  >tree)
                  >
                  >[/color]
                  Heya Jim,
                  The page I link to is standard XHTML 1.1 with document type and xml
                  prologue. It renders fine in IE 6 as HTML, not as an XML tree view, even
                  though IE doesn't recognize the document type.
                  [color=blue]
                  >
                  >[color=green]
                  >>at least if the document you're
                  >>calling is HTML. See the following two example pages in any browser:
                  >>http://slider142.com/xhtml/objecttest.xhtml - The base document is XHTML 1.1
                  >>http://slider142.com/xhtml/objecttest.html - The base document is HTML
                  >>4.01 Strict
                  >>
                  >>[/color]
                  >
                  >Use IFRAME.
                  >
                  >Jim.
                  >
                  >[/color]
                  I would use IFRAME as an example, but as it's been deprecated in XHTML
                  1.1 in favor of the coming XFrames standard, I decided to use object
                  instead. Even when writing HTML, I try to use elements that are
                  forwards-compatible for low maintenance.

                  Comment

                  • kaeli

                    #10
                    Re: Dynamic include files

                    In article <eYLtc.67614$cz 5.28354785@news 4.srv.hcvlny.cv .net>,
                    webmaster@slide r142.donttypeth is.com enlightened us with...[color=blue][color=green]
                    > >
                    > >[/color]
                    > Heya Jim,
                    > The page I link to is standard XHTML 1.1 with document type and xml
                    > prologue. It renders fine in IE 6 as HTML, not as an XML tree view, even
                    > though IE doesn't recognize the document type.
                    >[color=green]
                    > >[/color][/color]

                    Actually, I got a download dialog box when I tried to open it.


                    I have no clue what to do about that, but since I don't use xhtml, I
                    didn't worry about it.

                    --
                    --
                    ~kaeli~
                    You feel stuck with your debt if you can't budge it.



                    Comment

                    • Jim Ley

                      #11
                      Re: Dynamic include files

                      On Fri, 28 May 2004 18:57:14 GMT, Ron
                      <webmaster@slid er142.donttypet his.com> wrote:
                      [color=blue]
                      >Jim Ley wrote:[color=green]
                      >>no it does not, IE does not render XHTML 1.1. (other than as an XML
                      >>tree)
                      >>
                      >>[/color]
                      >Heya Jim,
                      > The page I link to is standard XHTML 1.1 with document type and xml
                      >prologue. It renders fine in IE 6 as HTML, not as an XML tree view, even
                      >though IE doesn't recognize the document type.[/color]

                      It doesn't render for me, I could make it render with some reg
                      hacking, but that's hardly a good thing, as it'll still be tag-soup,
                      and rendered badly.
                      [color=blue][color=green]
                      >>Use IFRAME.[/color]
                      >I would use IFRAME as an example, but as it's been deprecated in XHTML
                      >1.1 in favor of the coming XFrames standard, I decided to use object
                      >instead. Even when writing HTML, I try to use elements that are
                      >forwards-compatible for low maintenance.[/color]

                      Quick question then in a HTML doc embedded in OBJECT what does the A
                      element do - replace the object, or the parent - which is the spec
                      compliant way? (it's not defined I believe btw.)

                      Jim.

                      --
                      comp.lang.javas cript FAQ - http://jibbering.com/faq/

                      Comment

                      • Ron

                        #12
                        Re: Dynamic include files

                        Jim Ley wrote:
                        [color=blue]
                        >On Fri, 28 May 2004 18:57:14 GMT, Ron
                        ><webmaster@sli der142.donttype this.com> wrote:
                        >
                        >
                        >[color=green]
                        >> Heya Jim,[/color]
                        >[color=green]
                        >> The page I link to is standard XHTML 1.1 with document type and xml
                        >>[color=darkred]
                        >>> <>prologue. It renders fine in IE 6 as HTML, not as an XML tree
                        >>> view, even
                        >>> though IE doesn't recognize the document type.[/color]
                        >>[/color]
                        >
                        >It doesn't render for me, I could make it render with some reg
                        >hacking, but that's hardly a good thing, as it'll still be tag-soup,
                        >and rendered badly.
                        >
                        >[/color]
                        Hmm, you're right. The XHTML file only renders in IE when I load it from
                        my computer. It may be because of the extra MSXML stuff I have installed.
                        [color=blue]
                        >
                        >[color=green][color=darkred]
                        >>>Use IFRAME.
                        >>>
                        >>>[/color]
                        >>I would use IFRAME as an example, but as it's been deprecated in XHTML
                        >>1.1 in favor of the coming XFrames standard, I decided to use object
                        >>instead. Even when writing HTML, I try to use elements that are
                        >>forwards-compatible for low maintenance.
                        >>
                        >>[/color]
                        >
                        >Quick question then in a HTML doc embedded in OBJECT what does the A
                        >element do - replace the object, or the parent - which is the spec
                        >compliant way? (it's not defined I believe btw.)
                        >
                        >Jim.
                        >
                        >
                        >[/color]
                        The object behaves like an IFRAME in Mozilla. Ie., manually add the
                        'target="_paren t"' or "_top" attribute to links within, or use
                        javascript to cover all links automatically. Unfortunately, only
                        javascript seems to work for IE.

                        Comment

                        • Thomas 'PointedEars' Lahn

                          #13
                          Re: Dynamic include files

                          kaeli wrote:
                          [color=blue]
                          > [...] areynoldsx@hotm ail.com enlightened us with...[color=green]
                          >> Is it possible to use includes dynamically in html.[/color]
                          >
                          > Yes, but not with javascript, which runs on the client. [...][/color]

                          s/javascript, which runs on the client/client-side J(ava)Script/

                          There is server-side J(ava)Script as well.


                          PointedEars

                          Comment

                          • Thomas 'PointedEars' Lahn

                            #14
                            Re: Dynamic include files

                            kaeli wrote:
                            [color=blue]
                            > In article <s5stc.59999$cz 5.24777812@news 4.srv.hcvlny.cv .net>,
                            > webmaster@slide r142.donttypeth is.com enlightened us with...[color=green]
                            >> <object id="file1" data="file1.htm l" type="text/html" width="100%"
                            >> standby="Loadin g file1.html...">
                            >> Your browser cannot render embedded HTML documents.
                            >> </object>[/color]
                            >
                            > I really like this method. This is the first time I've seen it for html
                            > pages. Unfortunately, IE doesn't seem to support it.[/color]

                            Using the "object" element is not very different from using
                            the "iframe" element, and support is as well limited.
                            [color=blue]
                            > Does anyone know what browsers do support this?[/color]

                            All Mozilla/5.0 support it.
                            [color=blue]
                            > I tested Opera 7 and Netscape 7 and they were fine. IE 6, however,
                            > didn't render anything at all, even the warning that it isn't supported.
                            > Anyone test with Safari, Konqueror, etc? I assume Netscape 4 would not
                            > support it.[/color]

                            As it does not support the "iframe" element.
                            [color=blue]
                            > I used the following doctype for both html files:
                            > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
                            > "http://www.w3.org/TR/REC-html40/loose.dtd">
                            >
                            > Should I use a different one for this?[/color]

                            You could use HTML 4.01 Strict since the "object" element is specified
                            there. Depends on what other HTML features you use in the document.

                            <http://www.w3.org/TR/html4/struct/objects.html#ed ef-OBJECT>


                            X-Post & F'up2 comp.infosystem s.www.authoring.html

                            PointedEars

                            Comment

                            • Thomas 'PointedEars' Lahn

                              #15
                              Re: Dynamic include files

                              Ron wrote:
                              [color=blue]
                              > Heya Jim,[/color]

                              My name is not Jim.
                              [color=blue]
                              > The page I link to is standard XHTML 1.1 with document type and xml
                              > prologue. It renders fine in IE 6 as HTML, not as an XML tree view, even
                              > though IE doesn't recognize the document type.[/color]

                              XHTML served correctly as application/xhtml+xml does not render in IE at all
                              (I'm using the latest, Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0;
                              Q312461; .NET CLR 1.1.4322)), it wants to download the document since it
                              does not support the MIME type. And serving XHTML as text/html is utter
                              nonsense. As for XHTML, see my signature.


                              PointedEars
                              --
                              realism: HTML 4.01 Strict
                              evangelism: XHTML 1.0 Strict
                              madness: XHTML 1.1 as application/xhtml+xml
                              -- Bjoern Hoehrmann

                              Comment

                              Working...