473,625 Members | 2,999 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

JavaScript on Demand

I have an HTML page with included JS file like:
<script language="javas cript" type="text/javascript" src="file.js"></
script>

The file.js has a set of functions and global initializer for some
html object. Hoever, I want to hide my html object with display:block
CSS property. As a result, object in JS file fails to be initialized
for a hidden object. I decided to call JS file when needed (i.e. when
HTML object becomes visible on page) like this:

function getJSOnDemand() {
var head = document.getEle mentsByTagName( "head")[0];
var script = document.create Element('script ');
script.id = 'tinyMCEScriptI nitializer';
script.type = 'text/javascript';
script.src = "file.js";
head.appendChil d(script);
}

Howeverm it did not work and still fails to initialize HTML object, as
if it does not see it. Could you recommend how to call JS file when it
is needed or how to deal with initialization of the html object which
is hidden on the page?
Thank you.

May 25 '07 #1
6 2327
On 25 May 2007 07:19:22 -0700, in comp.lang.javas cript
vu******@gmail. com
<11************ **********@p47g 2000hsd.googleg roups.comwrote:
>| I have an HTML page with included JS file like:
| <script language="javas cript" type="text/javascript" src="file.js"></
| script>
|
| The file.js has a set of functions and global initializer for some
| html object. Hoever, I want to hide my html object with display:block
| CSS property. As a result, object in JS file fails to be initialized
| for a hidden object. I decided to call JS file when needed (i.e. when
| HTML object becomes visible on page) like this:
|
| function getJSOnDemand() {
| var head = document.getEle mentsByTagName( "head")[0];
| var script = document.create Element('script ');
| script.id = 'tinyMCEScriptI nitializer';
| script.type = 'text/javascript';
| script.src = "file.js";
| head.appendChil d(script);
| }
|
| Howeverm it did not work and still fails to initialize HTML object, as
| if it does not see it. Could you recommend how to call JS file when it
| is needed or how to deal with initialization of the html object which
| is hidden on the page?
| Thank you.
<body onload="getJSOn Demand();" >
---------------------------------------------------------------
jn******@yourpa ntsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
May 25 '07 #2
On May 25, 11:30 am, Jeff North <jnort...@yahoo .com.auwrote:
On 25 May 2007 07:19:22 -0700, in comp.lang.javas cript
vunet...@gmail. com

<1180102762.670 199.195...@p47g 2000hsd.googleg roups.comwrote:
| I have an HTML page with included JS file like:
| <script language="javas cript" type="text/javascript" src="file.js"></
| script>
|
| The file.js has a set of functions and global initializer for some
| html object. Hoever, I want to hide my html object with display:block
| CSS property. As a result, object in JS file fails to be initialized
| for a hidden object. I decided to call JS file when needed (i.e. when
| HTML object becomes visible on page) like this:
|
| function getJSOnDemand() {
| var head = document.getEle mentsByTagName( "head")[0];
| var script = document.create Element('script ');
| script.id = 'tinyMCEScriptI nitializer';
| script.type = 'text/javascript';
| script.src = "file.js";
| head.appendChil d(script);
| }
|
| Howeverm it did not work and still fails to initialize HTML object, as
| if it does not see it. Could you recommend how to call JS file when it
| is needed or how to deal with initialization of the html object which
| is hidden on the page?
| Thank you.

<body onload="getJSOn Demand();" >
---------------------------------------------------------------
jnort...@yourpa ntsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
I am sorry, I will supply more details:
- JS file initializes html object "textarea", I call it "TXT", without
problems
- I want to remove TXT and add it dynamically later
- So, JS cannot initialize anything in case above
- When TXT is added, I want to call JS at that moment only, using so-
called js on demand
- The problem is it does not initialize the TXT even though it is
successfully called

May 25 '07 #3
<body onload="getJSOn Demand();" >
---------------------------------------------------------------
jnort...@yourpa ntsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------

I am sorry, I will supply more details:
- JS file initializes html object "textarea", I call it "TXT", without
problems
what do you mean by "initialize s" the html object?
- I want to remove TXT and add it dynamically later
why do you add it, then remove it, then add it later? why not display
it statically from the start, but with css-style "hidden" or
"display:no ne", and then later just show it?
- So, JS cannot initialize anything in case above
- When TXT is added, I want to call JS at that moment only, using so-
called js on demand
what does it mean "when ... added, I want to call AT THAT MOMENT, ON
DEMAND"? It's rather automatically, when it's added, or on demand...
or do I not understand it well?
- The problem is it does not initialize the TXT even though it is
successfully called
what is called? and how do you fail "initializi ng" the TXT, if you
said you didn't have problems with this, in the first sentence?

Pretty confusing.
I think it is still Jeff North's advice you should listen to.

May 25 '07 #4
On May 25, 1:43 pm, Darko <darko.maksimo. ..@gmail.comwro te:
<body onload="getJSOn Demand();" >
---------------------------------------------------------------
jnort...@yourpa ntsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
I am sorry, I will supply more details:
- JS file initializes html object "textarea", I call it "TXT", without
problems

what do you mean by "initialize s" the html object?- I want to remove TXT and add it dynamically later

why do you add it, then remove it, then add it later? why not display
it statically from the start, but with css-style "hidden" or
"display:no ne", and then later just show it?- So, JS cannot initialize anything in case above
- When TXT is added, I want to call JS at that moment only, using so-
called js on demand

what does it mean "when ... added, I want to call AT THAT MOMENT, ON
DEMAND"? It's rather automatically, when it's added, or on demand...
or do I not understand it well?- The problem is it does not initialize the TXT even though it is
successfully called

what is called? and how do you fail "initializi ng" the TXT, if you
said you didn't have problems with this, in the first sentence?

Pretty confusing.
I think it is still Jeff North's advice you should listen to.
I am sorry... I do sound confusing.

History: I built a test case to initialize TinyMCE (html editor) which
was successfully implemented. In this test case, I include a JS file
which looks for a textarea on my page and some global method of
tinyMCE initializes some functionality, so I see the editor appended
to my textarea field.

My goal: My web app uses xmlhttp request to create a content for some
web page. The content is hidden by default (display:none). But the
user can select what content to display (display:block) .
The textarea which I apply tinyMCE to is within that hidden content.
Basically, I am lokking for the way to run a TinyMCE's JS file when
textarea's content is shown on the page.

That's all

I tried:
1) run the JS file on page load, but the required texarea does not
exist yet
2) call JS on demand when textarea is visible, but it does not work
and the TinyMCE's code fails to initialize with:

tinyMCE.init({
theme : "advanced",
mode : "exact",
elements : "Descriptio ns",
save_callback : "customSave ",
content_css : "example_advanc ed.css",
extended_valid_ elements : "a[href|target|nam e]",
plugins : "table",
theme_advanced_ buttons3_add_be fore : "tablecontrols, separator",
//invalid_element s : "a",
theme_advanced_ styles : "Header 1=header1;Heade r 2=header2;Heade r
3=header3;Table Row=tableRow1", // Theme specific setting CSS classes
//execcommand_cal lback : "myCustomExecCo mmandHandler",
debug : false
});

May 25 '07 #5
vu******@gmail. com wrote:
On May 25, 1:43 pm, Darko <darko.maksimo. ..@gmail.comwro te:
>>><body onload="getJSOn Demand();" >
---------------------------------------------------------------
jnort...@you rpantsyahoo.com .au : Remove your pants to reply
---------------------------------------------------------------
I am sorry, I will supply more details:
- JS file initializes html object "textarea", I call it "TXT", without
problems
what do you mean by "initialize s" the html object?- I want to remove TXT and add it dynamically later

why do you add it, then remove it, then add it later? why not display
it statically from the start, but with css-style "hidden" or
"display:none" , and then later just show it?- So, JS cannot initialize anything in case above
>>- When TXT is added, I want to call JS at that moment only, using so-
called js on demand
what does it mean "when ... added, I want to call AT THAT MOMENT, ON
DEMAND"? It's rather automatically, when it's added, or on demand...
or do I not understand it well?- The problem is it does not initialize the TXT even though it is
>>successfull y called
what is called? and how do you fail "initializi ng" the TXT, if you
said you didn't have problems with this, in the first sentence?

Pretty confusing.
I think it is still Jeff North's advice you should listen to.

I am sorry... I do sound confusing.

History: I built a test case to initialize TinyMCE (html editor) which
was successfully implemented. In this test case, I include a JS file
which looks for a textarea on my page and some global method of
tinyMCE initializes some functionality, so I see the editor appended
to my textarea field.

My goal: My web app uses xmlhttp request to create a content for some
web page. The content is hidden by default (display:none). But the
user can select what content to display (display:block) .
The textarea which I apply tinyMCE to is within that hidden content.
Basically, I am lokking for the way to run a TinyMCE's JS file when
textarea's content is shown on the page.

That's all

I tried:
1) run the JS file on page load, but the required texarea does not
exist yet
2) call JS on demand when textarea is visible, but it does not work
and the TinyMCE's code fails to initialize with:

tinyMCE.init({
theme : "advanced",
mode : "exact",
elements : "Descriptio ns",
save_callback : "customSave ",
content_css : "example_advanc ed.css",
extended_valid_ elements : "a[href|target|nam e]",
plugins : "table",
theme_advanced_ buttons3_add_be fore : "tablecontrols, separator",
//invalid_element s : "a",
theme_advanced_ styles : "Header 1=header1;Heade r 2=header2;Heade r
3=header3;Table Row=tableRow1", // Theme specific setting CSS classes
//execcommand_cal lback : "myCustomExecCo mmandHandler",
debug : false
});
Try reducing this to the most bare minimum possible, maybe:

tinyMCE.init({m ode: 'textareas'});

Every example I have ever seen issues the init() method without any
mention of DOM-readiness.

The above example does say "when the page loads," so I am guessing it is
DOM-loaded-friendly. I have no clue what TinyMCE does or doesn't do, so
you might try wrapping it in a function, and call that function if/when
your textarea appears.

Last but not least, whittle this down into a tiny example, post it
online and you might get more help.

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
May 25 '07 #6
On 25 May 2007 12:10:56 -0700, in comp.lang.javas cript
vu******@gmail. com
<11************ *********@p77g2 000hsh.googlegr oups.comwrote:
>| On May 25, 1:43 pm, Darko <darko.maksimo. ..@gmail.comwro te:
| <body onload="getJSOn Demand();" >
| ---------------------------------------------------------------
| jnort...@yourpa ntsyahoo.com.au : Remove your pants to reply
| ---------------------------------------------------------------
| >
| I am sorry, I will supply more details:
| - JS file initializes html object "textarea", I call it "TXT", without
| problems
| >
| what do you mean by "initialize s" the html object?- I want to remove TXT and add it dynamically later
| >
| why do you add it, then remove it, then add it later? why not display
| it statically from the start, but with css-style "hidden" or
| "display:no ne", and then later just show it?- So, JS cannot initialize anything in case above
| - When TXT is added, I want to call JS at that moment only, using so-
| called js on demand
| >
| what does it mean "when ... added, I want to call AT THAT MOMENT, ON
| DEMAND"? It's rather automatically, when it's added, or on demand...
| or do I not understand it well?- The problem is it does not initialize the TXT even though it is
| successfully called
| >
| what is called? and how do you fail "initializi ng" the TXT, if you
| said you didn't have problems with this, in the first sentence?
| >
| Pretty confusing.
| I think it is still Jeff North's advice you should listen to.
|
| I am sorry... I do sound confusing.
|
| History: I built a test case to initialize TinyMCE (html editor) which
| was successfully implemented. In this test case, I include a JS file
| which looks for a textarea on my page and some global method of
| tinyMCE initializes some functionality, so I see the editor appended
| to my textarea field.
|
| My goal: My web app uses xmlhttp request to create a content for some
| web page. The content is hidden by default (display:none). But the
| user can select what content to display (display:block) .
| The textarea which I apply tinyMCE to is within that hidden content.
| Basically, I am lokking for the way to run a TinyMCE's JS file when
| textarea's content is shown on the page.
Call the tinyMCE.init from within the function that displays the block
and after any further processing that needs to be done i.e.
document.getEle mentById("tinyM CE").style.disp lay="block";
do stuff
do stuff
tinyMCE = new etc etc
tinyMCE.init(.. ..
>| That's all
|
| I tried:
| 1) run the JS file on page load, but the required texarea does not
| exist yet
| 2) call JS on demand when textarea is visible, but it does not work
| and the TinyMCE's code fails to initialize with:
|
| tinyMCE.init({
| theme : "advanced",
| mode : "exact",
| elements : "Descriptio ns",
| save_callback : "customSave ",
| content_css : "example_advanc ed.css",
| extended_valid_ elements : "a[href|target|nam e]",
| plugins : "table",
| theme_advanced_ buttons3_add_be fore : "tablecontrols, separator",
| //invalid_element s : "a",
| theme_advanced_ styles : "Header 1=header1;Heade r 2=header2;Heade r
| 3=header3;Table Row=tableRow1", // Theme specific setting CSS classes
| //execcommand_cal lback : "myCustomExecCo mmandHandler",
| debug : false
| });
---------------------------------------------------------------
jn******@yourpa ntsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
May 25 '07 #7

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

Similar topics

53
5688
by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is difficult to know what is going on. One of these Order Forms you can see here... http://www.cardman.co.uk/orderform.php3
6
1340
by: TJ | last post by:
Hello All, I posted a question a few days ago entitled "Select element with no selected options". Over the course of the discussion, RobG wrote: > This is just an example, it is not really suitable for the web since > without JavaScript it doesn't work at all and whilst I've stuck to > standards, it will be intolerant of some (particularly older) browsers > - but it is a bit of fun trying to do some of this stuff and create > ...
6
1404
by: Marios Koumides | last post by:
I have a page written in ASP and I added some Javascript code to ensure the input boxes are filled with correct data. That check is performed every time the user moves out from a textbox. Now right before I submit the form to the server for processing, I want to make a final test on the values. <input type="submit" onClick="testResults(this.form)" value="Submit" > The problem here is that I make the check in the testResults function...
136
9296
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their code was littered with document.all and eval, for example, and I wanted to create a practical list of best practices that they could easily put to use. The above URL is version 1.0 (draft) that resulted. IMO, it is not a replacement for the FAQ,...
41
4921
by: Rene Nyffenegger | last post by:
Hello everyone. I am not fluent in JavaScript, so I might overlook the obvious. But in all other programming languages that I know and that have associative arrays, or hashes, the elements in the hash are alphabetically sorted if the key happens to be alpha numeric. Which I believe makes sense because it allows for fast lookup of a key.
6
2759
by: Venkatesh | last post by:
Hello All, I have couple of doubts regarding the concept of on-demand javascript loading using javascript code. I could see on the net different techniques for achieving this - techniques like: 1. document.write("<script src= language='JavaScript'></script>); 2. sc = document.createElement("<script>"); sc.setAttribute("src", ); and append this to the head
1
1506
by: menyki | last post by:
am writing a program to determine the best price that will attract maximum demand. first i had to generate random number to enable me determine the price and quantity demanded at the particular price. my problem is that the program has alot of errors. can u help me debug, please!!! i need it urgently. such error include unable to load include file stdio.h and so on. the source code is as shown below /* programe to solve mr jones problem....
6
1802
by: vinod | last post by:
Hi, The application we have developed uses JavaScript extensively. One of the users of the application is facing a problem. Instead of being hidden, the javascript code in the HTML is displayed or should I say, printed, on the browser. On viewing the rendered source, I'm seeing that all the "script" tags are rendered as "scrip!", "onLoad" as "onLoa!" in the HTML. Now I tried disabling Javascript on my browser but this did not happen with...
22
2889
by: Dan Rumney | last post by:
Hi all, I've been writing Javascript for quite a while now and have, of late, been writing quite a lot of AJAX and AJAX-related code. In the main, my dynamically generated pages are created using Perl on the backend, with Javascript providing limited frontend functionality. As an example, an expanding tree would be fully populated on the server-side and then presented to the browser, with Javascript and CSS being used to vary the...
0
8253
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
8635
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...
1
8354
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8497
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...
0
7182
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2621
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
1
1802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1499
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.