Queston on script tag

T

Torben Keil

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
 
H

Harlan Messinger

Torben said:
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.
 
J

Jeff

Torben said:
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
 
R

richard

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.
 
A

Andy Dingley

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.
 
T

Torben Keil

Andy said:
[...]
"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
 
T

Torben Keil

Harlan said:
[...]

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
 
H

Harlan Messinger

Torben said:
Harlan said:
[...]

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.
 
T

Toby A Inkster

Torben said:
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/
 
A

Andy Dingley

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.
 
R

rf

Torben Keil said:
Andy said:
[...]
"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 :)
 
H

Harlan Messinger

rf said:
Torben Keil said:
Andy said:
[...]
"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?
 
D

dorayme

Harlan Messinger said:
rf wrote:

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!
 
H

Harlan Messinger

dorayme said:
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.
 
D

dorayme

Harlan Messinger said:
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>
 

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
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top