473,407 Members | 2,320 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Creating Script on the Fly

Hi All,
I have a problem getting the following simple example
of "document.write" creating a script on the fly
to work in all html browsers.
It works in I.E., Firefox, and Netscape 7 above.
It doesn't seem to work in Netscape 4. Am I missing
something with it? When I look at page source in
Netscape 4 the script isn't even shown.
Can Netscape 4 create scripts on the fly at all?

thanx
Russ Kinter

<HTML>
<HEAD>
<script language="javascript">
function loadBrowser() {
var aStr = '<HTML>';
aStr += '<HTML>';
aStr += '<HEAD>';
aStr += '<SCRIPT language ="JavaScript">';
aStr += 'function vrmlHTML(){ ';
aStr += 'resizeTo(400,300);';
aStr += 'moveTo(0,0); }';
aStr += '<\/SCRIPT>';
aStr += ' <\/HEAD>';
aStr += ' <BODY onload="vrmlHTML()">';
aStr += '<\/BODY >';
aStr += '<\/HTML>';
document.open();
document.write(aStr);
document.close();
}
</SCRIPT>
</HEAD>
<BODY onload="loadBrowser()">
</BODY>
</HTML>

Jul 31 '05 #1
7 2122


Russ wrote:

I have a problem getting the following simple example
of "document.write" creating a script on the fly
to work in all html browsers. It doesn't seem to work in Netscape 4. Am I missing
something with it? When I look at page source in
Netscape 4 the script isn't even shown.
Can Netscape 4 create scripts on the fly at all?
Netscape 4 problem in 2005? As far as I remember it there are indeed
problems to document.write HTML with script in Netscape 4 and have the
script being parsed and available in the document.written page.

function loadBrowser() {
var aStr = '<HTML>';
aStr += '<HTML>';
Why two <HTML>?
aStr += '<HEAD>';
aStr += '<SCRIPT language ="JavaScript">';
aStr += 'function vrmlHTML(){ ';
aStr += 'resizeTo(400,300);';
aStr += 'moveTo(0,0); }';
aStr += '<\/SCRIPT>';


I am not sure I remember any safe strategy to get the script recognized
but things you could tried are
- try whether external script is loaded e.g.
<script src="file.js" type="text/javascript"></script>
- I think in some cases people successfully worked around the problem
by inserting some dummy script first (which Netscape 4 then ignored)
but which caused further scripts to be recognized so you could try
to document.write at least two <script> elements

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 31 '05 #2
Russ wrote:
Hi All,
I have a problem getting the following simple example
of "document.write" creating a script on the fly
to work in all html browsers.
It works in I.E., Firefox, and Netscape 7 above.
It doesn't seem to work in Netscape 4. Am I missing
something with it? When I look at page source in
Netscape 4 the script isn't even shown.
Can Netscape 4 create scripts on the fly at all?

thanx
Russ Kinter

<HTML>
<HEAD>
<script language="javascript">
function loadBrowser() {
var aStr = '<HTML>';
aStr += '<HTML>';
aStr += '<HEAD>';
aStr += '<SCRIPT language ="JavaScript">';
aStr += 'function vrmlHTML(){ ';
aStr += 'resizeTo(400,300);';
aStr += 'moveTo(0,0); }';
aStr += '<\/SCRIPT>';
aStr += ' <\/HEAD>';
aStr += ' <BODY onload="vrmlHTML()">';
aStr += '<\/BODY >';
aStr += '<\/HTML>';
document.open();
document.write(aStr);
document.close();
}


It doesn't help your problem, but you may find it faster for larger
chunks of HTML to use an array:

var aStr = [
'<HTML><HEAD>',
'<SCRIPT type="text/JavaScript">',
'function vrmlHTML(){ ',
'resizeTo(400,300);',
'moveTo(0,0); }',
'<\/SCRIPT>',
' <\/HEAD>',
' <BODY onload="vrmlHTML()">',
'<\/BODY >',
'<\/HTML>'
];
document.open();
document.write( aStr.join('') );
document.close();
Or you can just use a single document.write:

document.open();
document.write(
'<HTML><HEAD>',
'<SCRIPT type="text/JavaScript">',
'function vrmlHTML(){ ',
'resizeTo(400,300);',
'moveTo(0,0); }',
'<\/SCRIPT>',
' <\/HEAD>',
' <BODY onload="vrmlHTML()">',
'<\/BODY >',
'<\/HTML>'
);
document.close();
Both the above are a lot faster than string concatenation and are
easier to code (to me at least).

--
Rob
Jul 31 '05 #3
VK

Russ wrote:
Hi All,
I have a problem getting the following simple example
of "document.write" creating a script on the fly
to work in all html browsers.
It works in I.E., Firefox, and Netscape 7 above.
It doesn't seem to work in Netscape 4. Am I missing
something with it? When I look at page source in
Netscape 4 the script isn't even shown.
Can Netscape 4 create scripts on the fly at all?


As DevEdge went to hell knows where, you have to accept my weak memory
:-)
NN4 do not parse (so doesn't execute) JavaScript inserted into another
page or layer ising document.write()

The work around would be to put your script into myScript.js file. NN4
also stops parsing as soon as it sees '<script>' string in write()
statement. But you can cheat it rather easily by doing:

document.write('<scr');
document.write('ipt src="myScript.js">');
document.write('</scr');
document.write('ipt>');

The other known bug in NN4 was that any language indications were
ignored if an external script file was used. So don't bother with
"language" or "type".

Wht do you need this antique anyway?

Jul 31 '05 #4
RobG wrote:

"
Or you can just use a single document.write:

document.open();
document.write(
'<HTML><HEAD>',
'<SCRIPT type="text/JavaScript">',
'function vrmlHTML(){ ',
'resizeTo(400,300);',
'moveTo(0,0); }',
'<\/SCRIPT>',
'<\/HEAD>',
'<BODY onload="vrmlHTML()">',
'<\/BODY >',
'<\/HTML>'
;
document.close();
"

Hi Rob,

It's me again with more questions.

The single document.write you suggested would have been my solution
also, except I would have put the entire content in single quotes.
Because that's all I know.

My questions are why do you have it divided up into groups within single
quotes followed by commas, and how do you determine what each group will
be within the single quotes ?

Later, Art.

Aug 1 '05 #5
X l e c t r i c wrote:
RobG wrote:

"
Or you can just use a single document.write: [...]
Hi Rob,

It's me again with more questions.

The single document.write you suggested would have been my solution
also, except I would have put the entire content in single quotes.
Because that's all I know.

My questions are why do you have it divided up into groups within single
quotes followed by commas, and how do you determine what each group will
be within the single quotes ?


It can be one long string, but it's easier to read and maintain if you
use blocks just as if you were writing it as plain HTML or whatever.

Write the source, test it, insert quotes and commas using find/replace,
then copy & paste it into the document.write() statement.

--
Rob
Aug 1 '05 #6
VK said the following on 7/31/2005 8:37 AM:
Russ wrote:
Hi All,
I have a problem getting the following simple example
of "document.write" creating a script on the fly
to work in all html browsers.
It works in I.E., Firefox, and Netscape 7 above.
It doesn't seem to work in Netscape 4. Am I missing
something with it? When I look at page source in
Netscape 4 the script isn't even shown.
Can Netscape 4 create scripts on the fly at all?

As DevEdge went to hell knows where, you have to accept my weak memory
:-)
NN4 do not parse (so doesn't execute) JavaScript inserted into another
page or layer ising document.write()


Actually, it did. You could dynamically load a script, or external
script file, by opening a layer, write to it, and close the layer.
The work around would be to put your script into myScript.js file. NN4
also stops parsing as soon as it sees '<script>' string in write()
statement. But you can cheat it rather easily by doing:

document.write('<scr');
document.write('ipt src="myScript.js">');
document.write('</scr');
document.write('ipt>');
I have never seen, nor do I remember, that ever being a problem. But all
it would take is an escape in the <\/script> tag to cure that problem.
Why make it harder than it has to be?
The other known bug in NN4 was that any language indications were
ignored if an external script file was used. So don't bother with
"language" or "type".


That's not good advice to give. Always use the type attribute and let
the browser deal with it how it wants. Do not produce invalid code just
because one ancient browser ignores it.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Aug 1 '05 #7
RobG wrote:

"It can be one long string, but it's easier to read and maintain if you
use blocks just as if you were writing it as plain HTML or whatever.

Write the source, test it, insert quotes and commas using find/replace,
then copy & paste it into the document.write() statement."

Hi Rob,

Thanks for the explanation. It makes good sense to me. I have a couple
of pages where I put html code to a page with document.write. I'll go
back and arrange it this way. Great idea.

Later, Art.

Aug 1 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Robin Tucker | last post by:
Hi there, I have a database on my test machine that will need to be installed on users machines. I would like to create the database with the given schema on the users machine and also with...
8
by: mcmg | last post by:
Hi, I have an asp app that works fine on a windows xp machine but does not work on a windows 2000 server. I have the following code in my global.asa: <OBJECT RUNAT=Server SCOPE=SESSION...
4
by: Francois Keyeux | last post by:
hello everyone: i have a web site built using vbasic active server scripting running on iis (it works on either iis 50 and 60, but is designed for iis 50) i know how to create a plain text...
3
by: Craig Jurney | last post by:
Am having difficulty creating a dynamic <select> element using direct assignment to the element's option array (ie. someElement.option=new Option(someText, someValue);) that will work on Palm...
10
by: Ron Vecchi | last post by:
I am creating a custom web control that uses an enum for a property {Remote,InLine}. If the property is set to inline then text is read from the embedded resource and sent to the browser in the...
5
by: Praveen | last post by:
I have script files embedded as resources in my dll. During runtime, I would like to write it out into the app dir (or a app sub-dir) and send the appropriate virtual path to the client. This makes...
9
by: Joe Penora | last post by:
Hi All, How to add the HTML script when creating new ASPX page. After it is done I may need to add some Meta tags etc... but the html script is not there. Is there an option in the ASP.NET...
13
by: jkimbler | last post by:
As part of our QA of hardware and firmware for the company I work for, we need to automate some testing of devices and firmware. Since not everybody here knows C#, I'm looking to create a new...
1
by: skyson2ye | last post by:
Hi, guys: I have written a piece of code which utilizes Javascript in PHP to create a three level dynamic list box(Country, States/Province, Market). However, I have encountered a strange problem,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.