472,782 Members | 1,274 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Cant correctly load .js files when creating page dynamically in IE

I have an HTML page that loads fine including the .js file

<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<title>Untitled Document</title>
<script language="JavaScript" type="text/JavaScript" src="ve3d.js"
</script>

</head>
<body>
.......
.......
.......
</body>
</html>

but when I try and load a window and create the same text dynamically
the .js file reports syntax errors at arbitrary points ( eg closing
brackets )and the scripts cant be called from the body of the page.

The code Im using to generate the page follows.
Its just the above code with a .document.write before each line. As
you can see Ive split the </script> to </scr'+'ipt>' tag so thats not
the problem.

VE3DWindow = window.open('', 'VE3DWin',
'resizable=yes,width=400,height=400')
VE3DWindow.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML
4.01 Transitional//EN"')
VE3DWindow.document.write('"http://www.w3.org/TR/html4/loose.dtd">')
VE3DWindow.document.write('<html>')
VE3DWindow.document.write('<head>')
VE3DWindow.document.write('<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">')
VE3DWindow.document.write('<title>Untitled Document</title>')
VE3DWindow.document.write('<script language="JavaScript"
type="text/JavaScript" src="ve3d.js"></scr'+'ipt>')
VE3DWindow.document.write('</head>')
VE3DWindow.document.write('<body>')
.........
.........
.........
VE3DWindow.document.write('</body>')
VE3DWindow.document.write('</html>')
VE3DWindow.document.close()

Everything works fine in NN6.2 but I'm getting random syntax errors in
the js script in IE6.

It's the content of the ....... section that is the reason to create
the thing dynamically.
Any ideas appreciated, Jake
Jul 23 '05 #1
4 2586
Jake Lewis wrote:
[snip]

but when I try and load a window and create the same text dynamically
the .js file reports syntax errors at arbitrary points ( eg closing
brackets )and the scripts cant be called from the body of the page.

[snip]

I don't know what's wrong with your code, but there was a
discussion recently on the best way to write slabs of HTML
to a page. The consensus was to write your HTML to an
array, they use join() to concatenate it and write it to
the page. Some code is below.

Note that if you use an array, it's very easy to handle
long lines of text. This seems much easier than

VE3DWindow.document.write('<html>')

which is replaced by:

"<html>",

The reason I've used a button to create the page is because
using onload or similar will not work if popup blocking is
enabled - the browser will only open a new window in
response to a user action, not automatically.

<html>
<head>
<title>New Page</title>
<script type="text/javascript">
function loadWindow() {
var VE3DWindow = window.open('',
'VE3DWin','resizable=1,width=400,height=400')
var a = [
'<!DOCTYPE HTML PUBLIC ',
'"-//W3C//DTD HTML 4.01 Transitional//EN"',
'"http://www.w3.org/TR/html4/loose.dtd">',
'<html>',
'<head>',
'<meta http-equiv="Content-Type" ',
'content="text/html; charset=iso-8859-1">',
'<title>Untitled Document</title>',
'<script type="text/JavaScript" src="xx.js"></scr',
'ipt>',
'<script type="text/JavaScript">alert(location);</scr',
'ipt>',
'</head>',
'<body>',
'<p>Here is a page</p><p>here is some text</p>',
'<p>and some more text</p>',
'<form action=""><input type="button" ',
'value="Open Window"',
'onclick="xx();"></form>',
'</body>',
'</html>',
];
VE3DWindow.document.write(a.join(""))
VE3DWindow.document.close()
}
</script>
</head>
<body>
<form action="">
<input type="button" value="Open Window"
onclick="loadWindow();">
</form>
</body>
</html>
file xx.js:

function xx() {
alert('hi');
}
Jul 23 '05 #2
Jake Lewis wrote:
<snip>
VE3DWindow = window.open('', 'VE3DWin',
When no URL is provided for the call to window.open the about:blank URL
is used (and/or variants).

<snip> VE3DWindow.document.write('<script language="JavaScript"
type="text/JavaScript" src="ve3d.js"></scr'+'ipt>')

<snip> ^^^^^^^

This is a relative URL; relative to what exactly? If it is relative to
about:blank then the source loaded will be some sort of error
page/report, and that will be interpreted as a series of javascript
syntax errors.

As I recall (and it has been a long time since I have written anything
using pop-ups) you can get round the problem by:-

1. loading a small page from your own site into the new
window (which might produce timing issues if the document
has not finished loading when you start writing to it.
Avoidable by having the loaded page call-back into its
- opener - to signal that it is ready to be written to).

2. Write a BASE element into the HTML source using the
location.href property of the current page, so that URLs
employed in the written HTML will be relative to it.

Richard.
Jul 23 '05 #3
"Richard Cornford" <Ri*****@litotes.demon.co.uk> wrote in message news:<ck*******************@news.demon.co.uk>...
Jake Lewis wrote:
<snip>
VE3DWindow = window.open('', 'VE3DWin',
When no URL is provided for the call to window.open the about:blank URL
is used (and/or variants).


2. Write a BASE element into the HTML source using the
location.href property of the current page, so that URLs
employed in the written HTML will be relative to it.

Richard.


Thanks for the tip here - this seems to be the way to do it. The fact
that IE was producing a script error and bringing up the .js file led
me to believe it had found it correctly, but clearly it hadnt.

Cheers Jake
Jul 23 '05 #4
thanks, I was sure there was a more elegant way to do that. Best Wishes, Jake
Jul 23 '05 #5

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

Similar topics

11
by: Wolfgang Kaml | last post by:
I am not sure if this is more of an expert question, but I am sure that they are out there. I'd like to setup a general application or bin directory on my Win2003.Net Server that will hold some...
2
by: KnotKnormal | last post by:
I would like to dynamically load a HTML page (or a Word document), which is embedded in a table when the user clicks on a hyperlink to go from HTML page one to HTML page two. For example, I would...
1
by: Reza Nabi | last post by:
Bakground: I have a webform (LoadCtl.aspx) which loads the user control to a placeholder dynamically based on the ctlName querystring passed in the URL. Webform (LoadCtl.aspx) also passes a...
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: netasp | last post by:
hi all, how can I populate one aspx form when page is loading based on page ID? for example: loading page A (to search for VB code) would display labels and texboxes, dropdown lists all related...
6
by: Steve Hershoff | last post by:
Hi everyone, I've got a strange one here. There are two datagrids on my page, one nested within the other. I'll refer to them as the topmost and secondary datagrids. In the topmost...
1
by: =?Utf-8?B?cHJhYmh1XzI3Xzg0?= | last post by:
hi i am creating many radio RadioButtonList dynamically in page load.its working find.now i want to select a text in radio button(Autopostback is true for radio buttonlist) and find that text in...
2
by: robert112 | last post by:
This is quite a hard one guys. ***Some necessary back ground Info*** I have an asp.net 1.1 application that uses a WYSIWYG to return some html created by the user in the admin section of the...
2
by: Richard Coltrane | last post by:
Hi There, Does anyone know iwhy I can do this in VB.Net: <link rel="stylesheet" href="<%=Global_asax.GetApplicationPath() %>styles/main.css" type="text/css"> in the header of an aspx page...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.