473,772 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

innerHTML and variable scope

OK. I've had a trawl through past messages but can see nothing that
helps me, so...here goes...

I am writing a web application which, among other things, pushes a web
page to a user's browser.

In very simple terms:

- I have a script in hidden frame A which sets the document.locati on
of main frame B.

- Once the document has been loaded in frame B, the script updates the
document.body.i nnerHTML of that document.

(Pushing the URL alone is not enough, since I want to push values in
form fields etc)

This model works great if I am pushing simple web pages, but as soon
as the page I am pushing has complex javascript in it, bad things
start happening.

One such page has a load of js file includes, which are used for the
drop down menus. Loaded normally in the browser, all the js on this
page works fine. However, if the page has been pushed to the browser
using my system, I get lots of '(varname) is null or not an object'
errors when I try to use the menus.

Now this smacks of a var scope problem, or somesuch. But I have no
real idea.

Can anyone suggest what might be happening here, or has anyone come
across this problem before?

I can post up some code if you want, but I thought I'd just get a
general idea if anyone has come across this problem first.

Cheers in advance for any ideas thrown into the ring!
Jul 23 '05 #1
4 2628
Nick wrote:

<--snip-->
- Once the document has been loaded in frame B, the script updates the
document.body.i nnerHTML of that document.

<--snip-->
This model works great if I am pushing simple web pages, but as soon
as the page I am pushing has complex javascript in it, bad things
start happening.
<--snip-->
Can anyone suggest what might be happening here, or has anyone come
across this problem before?


Your problem is not one of scope, but of execution. If you "push" this code:

<script type="text/javascript">
alert('It executed');
</script>

You won't get the alert because it doesn't get executed.

Some possibilities:

document.write the frame instead of innerHTML.
Use createElement to create a script element and then append (as a
child), the data, or a src="someFile.j s" attribute.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq/
Jul 23 '05 #2
> Your problem is not one of scope, but of execution. If you "push" this code:

<script type="text/javascript">
alert('It executed');
</script>

You won't get the alert because it doesn't get executed.

Some possibilities:

document.write the frame instead of innerHTML.
Use createElement to create a script element and then append (as a
child), the data, or a src="someFile.j s" attribute.


OK Randy, I was doing some thinking last night, and thought I'd try
chasing up document.write as well. As an experiment, I took the source
code of my problematic page with pulldown menus, stuck it all in a
textarea, and wrote a very short script to document.write the contents
of that field out to another frame.

top.frames['two'].document.open( "about:blan k");
top.frames['two'].document.write ln(document.daf orm.sourcecode. value);
top.frames['two'].document.close ();

But it doesn't work! Again the problem is with the javascript in the
page being pushed. In the main body of this document, there is an
inline call to a js function which is defined in an external file
referenced in the HEAD. I get an "object expected" error meaning that
it can't find the function called on that line.

I'm guessing that when a document is built using document.write( ) the
different parts of the page - inline js, external js etc - are
executed in a different order.

Funnily enough, when I refresh the page that has been pushed, it WORKS
ABSOLUTELY FINE! So obviously the browser has built the page in the
right order on refresh.

Oh yeah: I tried splitting the source code into lines (using "split"
on newlines), and then writing out each line separately. I thought if
I wrote each line separately, it might affect the "parse order".

IE crashed after a few lines :(

Thanks for your other suggestions, too, but I feel that if I could get
either the document.locati on/innerHTML or document.write( ) models
working, that would be the best course.

Any further suggestions?

Cheers for your continuing help.

Nick
Jul 23 '05 #3
Nick wrote:
Your problem is not one of scope, but of execution. If you "push" this code:

<script type="text/javascript">
alert('It executed');
</script>

You won't get the alert because it doesn't get executed.

Some possibilities:

document.writ e the frame instead of innerHTML.
Use createElement to create a script element and then append (as a
child), the data, or a src="someFile.j s" attribute.

OK Randy, I was doing some thinking last night, and thought I'd try
chasing up document.write as well. As an experiment, I took the source
code of my problematic page with pulldown menus, stuck it all in a
textarea, and wrote a very short script to document.write the contents
of that field out to another frame.

top.frames['two'].document.open( "about:blan k");
top.frames['two'].document.write ln(document.daf orm.sourcecode. value);
top.frames['two'].document.close ();

But it doesn't work! Again the problem is with the javascript in the
page being pushed. In the main body of this document, there is an
inline call to a js function which is defined in an external file
referenced in the HEAD. I get an "object expected" error meaning that
it can't find the function called on that line.


The first test page I made is at:
www.hikksworld.com/frames/frameset1.html

It uses a text area to get the code, and document.write' s it to the
right hand frame. The code that is default in the textarea was the code
I was testing it with. It loads an external .js file and then executes
it onclick of the link it generates. So I am not sure why yours is not
working. The only major difference I see between mine and yours is that
I am not using .open('about:bl ank') but when I used it, it didn't seem
to make any difference.

I'm guessing that when a document is built using document.write( ) the
different parts of the page - inline js, external js etc - are
executed in a different order.
No. When the page is loaded, it is parsed in the order that you give it
unless you use a defer attribute (which I believe to be an IE-only
attribute, not sure because I never use it).
Funnily enough, when I refresh the page that has been pushed, it WORKS
ABSOLUTELY FINE! So obviously the browser has built the page in the
right order on refresh.

Oh yeah: I tried splitting the source code into lines (using "split"
on newlines), and then writing out each line separately. I thought if
I wrote each line separately, it might affect the "parse order".

IE crashed after a few lines :(
Splitting the source shouldn't matter, but it crashing IE could be a
side effect of it since its introducing more and more calls to
document.write. BTW, what version IE are you using?
Thanks for your other suggestions, too, but I feel that if I could get
either the document.locati on/innerHTML or document.write( ) models
working, that would be the best course.

Any further suggestions?


Are frames a requirement? It would be easier to "push" innerHTML into a
div tag and load the external .js files in the main page. Thereby
eliminating the problem. You could try that approach with the frames but
the external files would have to be re-written to handle the
cross-frames issues.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq/
Jul 23 '05 #4
hmm, i built page in js, worked great withteh includes then put it into
asp.. same problem as you, so i hardcopied teh included stuff into teh
page and now it works
Woody
any sugestion or comment made by me should be examined first for
validity and appropriateness before assuming i have any idea at all
what the heck i am talking about. I am not responsible for anything you
may see with my name attached to it, i think.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #5

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

Similar topics

2
5687
by: Keiron Waites | last post by:
Is there any way to use a variable.innerHTML = ""; instead of text.innerHTML = "";? It doesn't seem to work for me. Thanks, Keiron
6
10156
by: adamrfrench | last post by:
Let it be mentioned that Javascript is not my forte, so the solution to this could very well be a simple one. I am working on an AJAX function where I can pass a URL and the target ID in, and have the function update the target ID with the URL. There is a bit more to it then that, but that is the basics. my difficulty comes when I try to assign a variable to: "document.getElementById('-> var gose here <-').innerHTML"
23
19203
by: Russ Chinoy | last post by:
Hi, This may be a totally newbie question, but I'm stumped. If I have a function such as: function DoSomething(strVarName) { ..... }
17
34722
by: PJ | last post by:
Greetings... I have stumbled upon a small problem. I use Ajax to retrieve part of a page I need to update. I update a DIV element with the HTML contents I get from another page. It works fine. However the HTML have a SCRIPT tag that the browser should process, but
1
25699
pbmods
by: pbmods | last post by:
VARIABLE SCOPE IN JAVASCRIPT LEVEL: BEGINNER/INTERMEDIATE (INTERMEDIATE STUFF IN ) PREREQS: VARIABLES First off, what the heck is 'scope' (the kind that doesn't help kill the germs that cause bad breath)? Scope describes the context in which a variable can be used. For example, if a variable's scope is a certain function, then that variable can only be used in that function. If you were to try to access that variable anywhere else in...
0
35247
MMcCarthy
by: MMcCarthy | last post by:
We often get questions on this site that refer to the scope of variables and where and how they are declared. This tutorial is intended to cover the basics of variable scope in VBA for MS Access. For the sake of brevity I am sticking to common usage. Wherever the term procedure is used in this tutorial it actually refers to a subroutine or function. Definition of Scope The scope of a variable where this variable can be seen or accessed...
8
3218
by: Pratik Patel | last post by:
Hello, I used innerHTML to assign HTML content. but in my HTML page content have also some javascript function and it will run when page load. bu when HTML code assgin thru innerHTML then this javascript is not working. e.g. html content:
112
5478
by: istillshine | last post by:
When I control if I print messages, I usually use a global variable "int silent". When I set "-silent" flag in my command line parameters, I set silent = 1 in my main.c. I have many functions that may print some messages. foo(...) { if (!silent)
6
4255
by: PaPa | last post by:
I'm not sure this is a javascript issue or an HTML issue. I notice that when I extract the contents of a div using the innerHTML property (?), that I wind up with a literal variable (?) which exactly matches the contents of the div with one exception. It seems that whenever the code includes a tag which uses the forward slash against the closing bracket (say the break tag ..... />) that the browser, or HTML, or javascript, or...
0
9621
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10264
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10106
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9914
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7461
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5355
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4009
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3610
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.