Queston on script tag

Discussion in 'HTML' started by Torben Keil, Feb 8, 2008.

  1. Torben Keil

    Torben Keil Guest

    Hello,

    I try to load dynamic generated HTTP code into the browser.

    Here's what I'm trying to do (very short written):
    [DOCTYPE, html, head, title...]
    <body>
    <script type="text/html" charset="ISO-8859-1"
    src="http://....../cgi-bin/code.pl"></script>
    [...]
    </body>
    </html>

    My perl script is located on an Internet server which executes this script
    and returns clean HTML code with the right MIME-type.

    But this all doesn't work on the web browser. If I use the same but as
    javascript, it works.

    May be you have a hint for me what I'm doing wrong?

    Thanks in advance,
    Torben
     
    Torben Keil, Feb 8, 2008
    #1
    1. Advertising

  2. Torben Keil wrote:
    > Hello,
    >
    > I try to load dynamic generated HTTP code into the browser.
    >
    > Here's what I'm trying to do (very short written):
    > [DOCTYPE, html, head, title...]
    > <body>
    > <script type="text/html" charset="ISO-8859-1"
    > src="http://....../cgi-bin/code.pl"></script>
    > [...]
    > </body>
    > </html>
    >
    > My perl script is located on an Internet server which executes this script
    > and returns clean HTML code with the right MIME-type.


    If you had

    <script type="text/html">
    <p>Hello, world!</p>
    </script>

    it wouldn't work either. The HTML inside the script tags is clean, the
    script type is designated as text/html. Nevertheless, it won't work
    because HTML isn't script and the browser doesn't have any way to
    execute it as script.

    > But this all doesn't work on the web browser. If I use the same but as
    > javascript, it works.


    Because Javascript is script and the browser knows how to execute it.
     
    Harlan Messinger, Feb 8, 2008
    #2
    1. Advertising

  3. Torben Keil

    Andy Dingley Guest

    On 8 Feb, 15:42, Torben Keil <> wrote:

    > My perl script is located on an Internet server


    Where?
     
    Andy Dingley, Feb 8, 2008
    #3
  4. Torben Keil

    Jeff Guest

    Torben Keil wrote:
    > Hello,
    >
    > I try to load dynamic generated HTTP code into the browser.
    >
    > Here's what I'm trying to do (very short written):
    > [DOCTYPE, html, head, title...]
    > <body>
    > <script type="text/html" charset="ISO-8859-1"
    > src="http://....../cgi-bin/code.pl"></script>
    > [...]
    > </body>
    > </html>
    >
    > My perl script is located on an Internet server which executes this script
    > and returns clean HTML code with the right MIME-type.


    If you run "head" on that script what mime type does it return?

    I don't seem to have head on my XP box, but I've had it on every other
    OS, anyone know how to add it?

    Jeff
    >
    > But this all doesn't work on the web browser. If I use the same but as
    > javascript, it works.
    >
    > May be you have a hint for me what I'm doing wrong?
    >
    > Thanks in advance,
    > Torben
     
    Jeff, Feb 8, 2008
    #4
  5. Torben Keil

    richard Guest

    On Fri, 08 Feb 2008 16:42:05 +0100, Torben Keil <>
    wrote:

    >Hello,
    >
    >I try to load dynamic generated HTTP code into the browser.
    >
    >Here's what I'm trying to do (very short written):
    >[DOCTYPE, html, head, title...]
    > <body>
    > <script type="text/html" charset="ISO-8859-1"
    >src="http://....../cgi-bin/code.pl"></script>
    >[...]
    > </body>
    ></html>
    >
    >My perl script is located on an Internet server which executes this script
    >and returns clean HTML code with the right MIME-type.
    >
    >But this all doesn't work on the web browser. If I use the same but as
    >javascript, it works.
    >
    >May be you have a hint for me what I'm doing wrong?
    >
    >Thanks in advance,
    >Torben



    There is no "text/html".
    charset is totally placed wrong.
    "src=" Huh? What are you trying to call?
    If anything, you would use a relative link.

    I would suggest you contact your host and ask them why it does not
    work.
     
    richard, Feb 10, 2008
    #5
  6. Torben Keil

    Andy Dingley Guest

    On 10 Feb, 05:09, richard <> wrote:
    > On Fri, 08 Feb 2008 16:42:05 +0100, Torben Keil <>
    > wrote:


    > > <script type="text/html" charset="ISO-8859-1"
    > >src="http://....../cgi-bin/code.pl"></script>


    > There is no "text/html".
    > charset is totally placed wrong.
    > "src=" Huh? What are you trying to call?
    > If anything, you would use a relative link.


    Ah, Mr Bullis, we meet again and you're still no wiser.For the sake of
    the OP who might not realise that you're the infamous "Richard The
    Stupid" (just Google it), the trolls' friend and the truckers' VK,
    here's a few pointers:


    First off, read the W3C spec:
    <http://www.w3.org/TR/html401/interact/scripts.html#edef-SCRIPT>

    "text/html" is a perfectly legitimate MIME content-type, as usually
    served through a HTTP header. It means HTML though, not JavaScript, so
    it's the wrong value in this case. The OP should use "text/javascript"
    instead, because the content that his Perl script is producing is
    intended to be JavaScript.

    Most importantly though, that server-side Perl script should return it
    too, and return it correctly as "text/javascript".

    charset is perfectly correct. It's a valid attribute on <script>, it's
    a valid value. Personally I'd use utf-8 instead, and I'd ignore this
    attribute and just let the target script set it in a HTTP header.
    However the OP isn't _wrong_ here.

    The src attribute is also fine. It refers to a CGI script on a server,
    and probably a Perl script. Now the idea of generating JavaScript from
    Perl strikes me as over-complex, hard to debug, and probably not a
    good idea, but it's the OP's problem to worry about that level.

    "use a relative link" is the one place where you're not crudely wrong,
    but then even a broken clock is right twice a day.

    A relative URL would probably be a bit easier for long-term
    maintenance, as it doesn't embed a domain or hostname than might
    change in the future. However this should be a relative URL using an
    abs_path (beginning with "/" such as /scripts/my_project/foo.pl )_ and
    _not_ as you'd probably do it with a rel_path beginning "../" or
    similar. Those can, and likely will be, be very awkward to maintain as
    content is moved around directories.
     
    Andy Dingley, Feb 10, 2008
    #6
  7. Torben Keil

    Torben Keil Guest

    Andy Dingley wrote:

    > [...]
    > "text/html" is a perfectly legitimate MIME content-type, as usually
    > served through a HTTP header. It means HTML though, not JavaScript, so
    > it's the wrong value in this case. The OP should use "text/javascript"
    > instead, because the content that his Perl script is producing is
    > intended to be JavaScript.


    My Perl-Script returns clean HTML code. That's why I decided to use
    "text/html" as MIME type. And using "application/JavaScript" is working
    when I'm linking to JavaScript code on the remote server.

    But I whish to embedd the produced HTML code of the perl script in the
    website.

    > [...]


    Greetings,
    Torben
     
    Torben Keil, Feb 11, 2008
    #7
  8. Torben Keil

    Torben Keil Guest

    Harlan Messinger wrote:

    > [...]
    >
    > If you had
    >
    > <script type="text/html">
    > <p>Hello, world!</p>
    > </script>
    >
    > it wouldn't work either. The HTML inside the script tags is clean, the
    > script type is designated as text/html. Nevertheless, it won't work
    > because HTML isn't script and the browser doesn't have any way to
    > execute it as script.
    >
    >> But this all doesn't work on the web browser. If I use the same but as
    >> javascript, it works.

    >
    > Because Javascript is script and the browser knows how to execute it.


    Okay JavaScript has to be executed. But a browser should normally know how
    to handle HTML...?

    Is this possibility of embedding of HTML in a website via the script tag
    forbidden? Maybe you or someone else can tell me why this must not work?

    Greetings,
    Torben
     
    Torben Keil, Feb 11, 2008
    #8
  9. Torben Keil wrote:
    > Harlan Messinger wrote:
    >
    >> [...]
    >>
    >> If you had
    >>
    >> <script type="text/html"> <p>Hello, world!</p> </script>
    >>
    >> it wouldn't work either. The HTML inside the script tags is clean,
    >> the script type is designated as text/html. Nevertheless, it won't
    >> work because HTML isn't script and the browser doesn't have any way
    >> to execute it as script.
    >>
    >>> But this all doesn't work on the web browser. If I use the same
    >>> but as javascript, it works.

    >> Because Javascript is script and the browser knows how to execute
    >> it.

    >
    > Okay JavaScript has to be executed. But a browser should normally
    > know how to handle HTML...?


    Sure, in places where it expects HTML. Then you tell it, "OK, here's
    some script to execute," but you turn around and give it something that
    isn't executable script, and expect the browser magically to know that
    you really didn't mean what you said. You can't just make stuff up and
    then expect it to work.

    > Is this possibility of embedding of HTML in a website via the script
    > tag forbidden? Maybe you or someone else can tell me why this must
    > not work?


    It has nothing to do with anything being *forbidden*. A SCRIPT tag means
    what it means. By using one you're telling the browser "Here's some
    script I want you to execute", but then you're giving it something that
    isn't executable script. The browser isn't going to realize what's going
    on and look at you with a sly grin and say, "Oh, you silly, you played a
    *trick* on me" and then ignore the SCRIPT tag and do what you hoped it
    would do.
     
    Harlan Messinger, Feb 11, 2008
    #9
  10. Torben Keil

    Bergamot Guest

    Bergamot, Feb 11, 2008
    #10
  11. Torben Keil wrote:

    > But I whish to embedd the produced HTML code of the perl script in the
    > website.


    The <script> element can *only* be used to include content in a supported
    client-side scripting language (usually Javascript, though Internet
    Explorer supports VBScript, and some experimental browsers and plugins
    support other client-side scripting languages).

    Other content (e.g. images, HTML, spreadsheets, Java applets, etc) cannot
    be included with <script>. They should be included using <object> instead.
    There are several other elements which are similar to <object> which may
    be used in preference to <object> is certain circumstances:

    * <img> is better supported for images
    * <applet> has better backwards compatibility for Java applets
    * Ditto <iframe> for text/html and text/plain

    So your code should be along these lines:

    <iframe type="text/html" charset="ISO-8859-1"
    src="http://....../cgi-bin/code.pl"></iframe>

    or:

    <object type="text/html" charset="ISO-8859-1"
    data="http://....../cgi-bin/code.pl"></object>

    --
    Toby A Inkster BSc (Hons) ARCS
    [Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
    [OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 12 days, 18:08.]

    Mince & Dumplings
    http://tobyinkster.co.uk/blog/2008/02/10/mince-dumplings/
     
    Toby A Inkster, Feb 11, 2008
    #11
  12. Torben Keil

    Torben Keil Guest

    Hi Toby,

    thanks for your answer. I'll test the object tag.

    Greetings,
    Torben
     
    Torben Keil, Feb 11, 2008
    #12
  13. Torben Keil

    Andy Dingley Guest

    On 11 Feb, 07:54, Torben Keil <> wrote:

    > But I whish to embedd the produced HTML code of the perl script in the website.


    In that case, assemble _all_ the content server-side and serve it as
    one single, simple HTML document.

    You could assemble thing client-side, using either <iframe> or
    <object>. <object> is probably preferable (if anyone has hard
    evidence against its support, I'd love to know about it). However this
    "asks more of the clients", so is always going to be more complicated
    to make simple and reliable. Doing it purely server-side is nice and
    simple from the client's viewpoint, thus safe & reliable.

    PS - Web scripting has moved on a _lot_ from Perl and CGI. Lots of
    better ways out there these days.
     
    Andy Dingley, Feb 12, 2008
    #13
  14. Torben Keil

    rf Guest

    "Torben Keil" <> wrote in message
    news:47afff4e$0$2302$-online.net...
    > Andy Dingley wrote:
    >
    >> [...]
    >> "text/html" is a perfectly legitimate MIME content-type, as usually
    >> served through a HTTP header. It means HTML though, not JavaScript, so
    >> it's the wrong value in this case. The OP should use "text/javascript"
    >> instead, because the content that his Perl script is producing is
    >> intended to be JavaScript.

    >
    > My Perl-Script returns clean HTML code. That's why I decided to use
    > "text/html" as MIME type. And using "application/JavaScript" is working
    > when I'm linking to JavaScript code on the remote server.
    >
    > But I whish to embedd the produced HTML code of the perl script in the
    > website.


    I've been watching this thread for a while waiting for someone to tell you
    what you are doing wrong :)

    You seem to be wanting to include a fragment of HTML (be it generated by a
    Perl script or whatever) using the script element, specifying in the src
    attribute your fragment of HTML (be it generated by a Perl script or
    whatever).

    Well, this is not going to happen. The script element is for linking in
    script, usually javascript. Not HTML fragments.

    The browser, when it sees a script element gathers the content of that
    element and hands it over to the scripting engine. It will not, ever,
    "include" that content as an HTML fragment, no matter what mime type you
    specify.

    Just like the content of a style element is handed over to the CSS parser.

    Andy has it right. This sort of including of HTML fragments is done server
    side, possibly by using a Perl script to generate the entire page, including
    bits and pieces as you see fit. This is not done client side.

    You *could* in your script element specify a bunch of javascript that does
    document.writes of some HTML but you really don't want to do that in this
    century :)

    --
    Richard.
     
    rf, Feb 12, 2008
    #14
  15. rf wrote:
    > "Torben Keil" <> wrote in message
    > news:47afff4e$0$2302$-online.net...
    >> Andy Dingley wrote:
    >>
    >>> [...]
    >>> "text/html" is a perfectly legitimate MIME content-type, as usually
    >>> served through a HTTP header. It means HTML though, not JavaScript, so
    >>> it's the wrong value in this case. The OP should use "text/javascript"
    >>> instead, because the content that his Perl script is producing is
    >>> intended to be JavaScript.

    >> My Perl-Script returns clean HTML code. That's why I decided to use
    >> "text/html" as MIME type. And using "application/JavaScript" is working
    >> when I'm linking to JavaScript code on the remote server.
    >>
    >> But I whish to embedd the produced HTML code of the perl script in the
    >> website.

    >
    > I've been watching this thread for a while waiting for someone to tell you
    > what you are doing wrong :)
    >
    > You seem to be wanting to include a fragment of HTML (be it generated by a
    > Perl script or whatever) using the script element, specifying in the src
    > attribute your fragment of HTML (be it generated by a Perl script or
    > whatever).
    >
    > Well, this is not going to happen. The script element is for linking in
    > script, usually javascript. Not HTML fragments.


    You waited too long. I explained this to him four days ago and then
    again yesterday. Have you plonked me?
     
    Harlan Messinger, Feb 12, 2008
    #15
  16. Torben Keil

    dorayme Guest

    In article <>,
    Harlan Messinger <> wrote:

    > rf wrote:


    > > I've been watching this thread for a while waiting for someone to tell you
    > > what you are doing wrong :)

    >
    > You waited too long. I explained this to him four days ago and then
    > again yesterday. Have you plonked me?


    I don't think so, those kf's I am not forced into, I sometimes
    visit voluntarily (something I do a bit, a bit like a layman
    prison visitor, to see that the inmates are not being ill treated
    too badly) and you were not there last time I visited rf's. He
    has some pretty rough characters in there and I was glad to get
    out. (No, he does not ill treat them, he is strict but fair; that
    is from my official diary and report in case you are curious).

    Boy, I could tell you some stories about kfs!

    --
    dorayme
     
    dorayme, Feb 12, 2008
    #16
  17. dorayme wrote:
    > In article <>,
    > Harlan Messinger <> wrote:
    >
    >> rf wrote:

    >
    >>> I've been watching this thread for a while waiting for someone to tell you
    >>> what you are doing wrong :)

    >> You waited too long. I explained this to him four days ago and then
    >> again yesterday. Have you plonked me?

    >
    > I don't think so, those kf's I am not forced into, I sometimes
    > visit voluntarily (something I do a bit, a bit like a layman
    > prison visitor, to see that the inmates are not being ill treated
    > too badly) and you were not there last time I visited rf's. He
    > has some pretty rough characters in there and I was glad to get
    > out. (No, he does not ill treat them, he is strict but fair; that
    > is from my official diary and report in case you are curious).
    >
    > Boy, I could tell you some stories about kfs!


    Ha! Listen, Junior, I can tell *you* stories. Barely had I been on
    Usenet, at least 12 years ago, when I found myself on the Vladimir Fomin
    Blacklist of Net.Nazis and Sandlot Bullies. The worst kind of social
    detritus was in there. It took me years afterwards to reacclimate myself
    to life in the outside world.
     
    Harlan Messinger, Feb 12, 2008
    #17
  18. Torben Keil

    dorayme Guest

    In article <>,
    Harlan Messinger <> wrote:

    > dorayme wrote:
    > > In article <>,
    > > Harlan Messinger <> wrote:
    > >
    > >> rf wrote:

    > >
    > >>> I've been watching this thread for a while waiting for someone to tell
    > >>> you
    > >>> what you are doing wrong :)
    > >> You waited too long. I explained this to him four days ago and then
    > >> again yesterday. Have you plonked me?

    > >
    > > I don't think so, those kf's I am not forced into, I sometimes
    > > visit voluntarily (something I do a bit, a bit like a layman
    > > prison visitor, to see that the inmates are not being ill treated
    > > too badly) and you were not there last time I visited rf's. He
    > > has some pretty rough characters in there and I was glad to get
    > > out. (No, he does not ill treat them, he is strict but fair; that
    > > is from my official diary and report in case you are curious).
    > >
    > > Boy, I could tell you some stories about kfs!

    >
    > Ha! Listen, Junior, I can tell *you* stories. Barely had I been on
    > Usenet, at least 12 years ago, when I found myself on the Vladimir Fomin
    > Blacklist of Net.Nazis and Sandlot Bullies. The worst kind of social
    > detritus was in there. It took me years afterwards to reacclimate myself
    > to life in the outside world.


    Wow, that does sound like a bad one! Must put it on my list for
    an official visit. <g>

    --
    dorayme
     
    dorayme, Feb 12, 2008
    #18
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. lezah
    Replies:
    7
    Views:
    787
    Mike Treseler
    Mar 2, 2004
  2. shruds
    Replies:
    1
    Views:
    871
    John C. Bollinger
    Jan 27, 2006
  3. =?Utf-8?B?WWFua2VlIEltcGVyaWFsaXN0IERvZw==?=

    ObjectDataSource queston (posted else where Sorry it was a mistake

    =?Utf-8?B?WWFua2VlIEltcGVyaWFsaXN0IERvZw==?=, Jul 18, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    400
    =?Utf-8?B?WWFua2VlIEltcGVyaWFsaXN0IERvZw==?=
    Jul 18, 2007
  4. Andy B.

    MVC2 form validation queston

    Andy B., Mar 7, 2010, in forum: ASP .Net
    Replies:
    0
    Views:
    707
    Andy B.
    Mar 7, 2010
  5. Dave L

    Queston on Double Partial PostBack

    Dave L, Apr 17, 2010, in forum: ASP .Net
    Replies:
    0
    Views:
    331
    Dave L
    Apr 17, 2010
Loading...

Share This Page