Cannot dynamically create iframe

B

BananaQuaalude

I'm getting the following error when I try to dynamically create an
iframe:

Error: Expected hexadecimal digit

This only occurs when I try to give the iframe a src value. If I leave
out the src, no error. Any ideas?

Here is the code:

var d=document;
if(d.getElementById && d.createElement && d.body &&
d.body.appendChild && typeof d.body.innerHTML != "undefined") {
var
Block = d.getElementById("childrenBlock"),
index = getLineItemCount();
//alert(index)
var container = d.createElement("div");
container.innerHTML =

"<div id='FileUpload" + index + "' class=Text><iframe frameborder=0
width=100% height=30% " +
"scrolling=no border=0 id='demo' name='demo' src='NewUpload
\upload2\demo.asp'></iframe></div>" +

Block.appendChild(container);

There's quite a bit of code (other form elements) before and after the
iframe I'm trying to create, but if I comment out the iframe, or just
don't give it a src value, I get no errors.

Is this just a simple formatting issue?

Thanks!
 
T

Thomas 'PointedEars' Lahn

BananaQuaalude said:
I'm getting the following error when I try to dynamically create an
iframe:

Error: Expected hexadecimal digit

This only occurs when I try to give the iframe a src value. If I leave
out the src, no error. Any ideas?
[...]
var container = d.createElement("div");
container.innerHTML =

"<div id='FileUpload" + index + "' class=Text><iframe frameborder=0
width=100% height=30% " +
"scrolling=no border=0 id='demo' name='demo' src='NewUpload
\upload2\demo.asp'></iframe></div>" +
^^
You confuse Web and WinDOS which is why you create the start delimiter of a
Unicode character escape sequence -- \u -- that has to be followed by the
hexadecimal code point value of the character.

Always delimit path components in URIs with `/'.


PointedEars
 
B

BananaQuaalude

BananaQuaalude said:
I'm getting the following error when I try to dynamically create an
iframe:
Error: Expected hexadecimal digit
This only occurs when I try to give the iframe a src value. If I leave
out the src, no error. Any ideas?
[...]
var container = d.createElement("div");
container.innerHTML =
"<div id='FileUpload" + index + "' class=Text><iframe frameborder=0
width=100% height=30% " +
"scrolling=no border=0 id='demo' name='demo' src='NewUpload
\upload2\demo.asp'></iframe></div>" +

^^
You confuse Web and WinDOS which is why you create the start delimiter of a
Unicode character escape sequence -- \u -- that has to be followed by the
hexadecimal code point value of the character.

Always delimit path components in URIs with `/'.

PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann- Hide quoted text -

- Show quoted text -

Okay, I understand I need an escape character, but I'm not sure which
one. Did you mean to say "Always delimit path components in URLs" with
`/' instead of "URIs"?

I've tried many combinations of \u and `/' but I still get the same
error. This goes inside the single quote, correct?

Thanks!
 
S

Stevo

BananaQuaalude said:
Okay, I understand I need an escape character, but I'm not sure which
one. Did you mean to say "Always delimit path components in URLs" with
`/' instead of "URIs"?
I've tried many combinations of \u and `/' but I still get the same
error. This goes inside the single quote, correct?

What Thomas was saying is that your src path should look like this:

src='NewUpload/upload2/demo.asp'

Using / instead of \

Using backslashes in paths doesn't work on web URI's, and also doesn't
work in JavaScript strings. The \ character is an escape character
giving special meaning to the character that follows. In your example
you've got \u and \d in your string.

If you're receiving your string like that, then you should replace them
using something like this:

s=s.replace(/\\/g,"/");
 
B

BananaQuaalude

What Thomas was saying is that your src path should look like this:

src='NewUpload/upload2/demo.asp'

Using / instead of \

Using backslashes in paths doesn't work on web URI's, and also doesn't
work in JavaScript strings. The \ character is an escape character
giving special meaning to the character that follows. In your example
you've got \u and \d in your string.

If you're receiving your string like that, then you should replace them
using something like this:

s=s.replace(/\\/g,"/");- Hide quoted text -

- Show quoted text -

Wow.

Well, that's what happens when you're coding at the end of a long day.

Thank you both for pointing out the obvious. I needed it!
 

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,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top