473,382 Members | 1,424 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,382 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 2120


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,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...

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.