473,785 Members | 2,919 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multithreading? Or the equivalent?

Is there a way to achieve multithreading in JavaScript? I'm looking to
fetch a page into a div while allowing the user to interact with another
div. At some point the newly fetched page contents will be available to the
div that the user is working in but I don't want to cause unnecessary
blocking. I've thought of using frames (would prefer divs) plus timeouts
and checking for when a load completes. Does anyone have an idea of how
this could work?
Jul 23 '05 #1
8 4013
You can have a SCRIPT element
<SCRIPT type='text/javascript' id=comm1></SCRIPT>
and set the src attribute like so:
document.getEle mentById('comm1 ') = 'dome.js'

At the end of your dome.js file you should do a
window.setTimeo ut() of whatever function you have in
your original page waiting to be run.

I don't know that I'd call this multithreading though.
Also, you should figure out how you want to deal
with the server not returning the .js file in time/at all.

Csaba Gabor from Budapest

"Mark" <Ma*******@gems .gov.bc.ca> wrote in message
news:40******@o bsidian.gov.bc. ca...
Is there a way to achieve multithreading in JavaScript? I'm looking to
fetch a page into a div while allowing the user to interact with another
div. At some point the newly fetched page contents will be available to the div that the user is working in but I don't want to cause unnecessary
blocking. I've thought of using frames (would prefer divs) plus timeouts
and checking for when a load completes. Does anyone have an idea of how
this could work?

Jul 23 '05 #2
Mark wrote:
Is there a way to achieve multithreading in JavaScript? I'm looking to
fetch a page into a div while allowing the user to interact with another
div. At some point the newly fetched page contents will be available to the
div that the user is working in but I don't want to cause unnecessary
blocking. I've thought of using frames (would prefer divs) plus timeouts
and checking for when a load completes. Does anyone have an idea of how
this could work?


Using setTimeout and setInterval, you can achieve a "multi-threaded"
effect. You need to make sure that nothing really blocks though.
You can use setInterval to do a periodic check if the data is ready, and
unschedule the interval once the task has completed.

You can use IFRAMES to load data in the background. You can set the
visibility to hidden, and the user will never see the page loading.
Once the page is loaded, you can set the visibility to show, and you
should be able to achieve what you want.

B

Jul 23 '05 #3


Mark wrote:
Is there a way to achieve multithreading in JavaScript? I'm looking to
fetch a page into a div while allowing the user to interact with another
div. At some point the newly fetched page contents will be available to the
div that the user is working in but I don't want to cause unnecessary
blocking. I've thought of using frames (would prefer divs) plus timeouts
and checking for when a load completes. Does anyone have an idea of how
this could work?


Client side JavaScript so far doesn't have any threading constructs but
it is event based and you can start loading an image for instance with
var img = new Image();
img.src = 'whatever.gif';
which the browser usually then does in a thread of its own and if you
have registered an onload event listener e.g
var img = new Image();
img.onload = function (evt) {
alert(this.src + ' loaded.');
};
img.src = 'whatever.gif';
then your event listener will be called once the image is loaded.

Some browsers like IE5+/Win and Netscape 6/7 and Mozilla based browsers
have special objects allowing you to make asynchronous HTTP requests and
set up event listeners to handle the response:
var httpRequest;
if (typeof ActiveXObject != 'undefined') {
httpRequest = new ActiveXObject(' Msxml2.XMLHTTP' );
}
else if (typeof XMLHttpRequest != 'undefined') {
httpRequest = new XMLHttpRequest( );
}
if (httpRequest) {
//open(httpReques tMethod, URL, async)
httpRequest.ope n('GET', 'whatever.html' , true);
httpRequest.onr eadystatechange = function () {
if (httpRequest.re adyState == 4) {
alert(httpReque st.responseText );
}
};
httpRequest.sen d(null);
}

That being demonstrated you should first consider making a site that
simply loads your page into an HTML iframe as that doesn't depend on
scripting being supported and enabled and should give you all the
advantages of interactivity and threaded request/response processing.
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 23 '05 #4
Csaba Gabor wrote:
You can have a SCRIPT element
<SCRIPT type='text/javascript' id=comm1></SCRIPT>
and set the src attribute like so:
document.getEle mentById('comm1 ') = 'dome.js'


Assuming you meant document.getEle mentById('comm1 ').src instead, one
should still be careful about attempting to change the src attribute of
a script tag. It does not work in all browsers. It works (as in, it
loads the .js file), in IE5.0, 5.5, 6.0 Windows, IE5 Mac and Opera
7/Windows (at least version 7.23 does), but does *not* work in any other
browser that I am aware of. If you know of a browser/OS combination
where it works that is not listed, could you please let me know browser,
revision, and OS?


--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq/
Jul 23 '05 #5
On Wed, 28 Apr 2004 22:00:59 +0200, Csaba Gabor <ne**@CsabaGabo r.com>
wrote:
You can have a SCRIPT element
<SCRIPT type='text/javascript' id=comm1></SCRIPT>
and set the src attribute like so:
document.getEle mentById('comm1 ') = 'dome.js'

At the end of your dome.js file you should do a
window.setTimeo ut() of whatever function you have in
your original page waiting to be run.

I don't know that I'd call this multithreading though.
Also, you should figure out how you want to deal
with the server not returning the .js file in time/at all.


In addition to what Randy said, you should be aware that the SCRIPT
element doesn't support an id attribute under any version of HTML or
XHTML. This has two implications:

1) You can't write valid HTML of any kind (unless you use your own DTD)
2) Strictly conforming browsers shouldn't return a SCRIPT element that has
a matching id.

Mike
Please don't top-post.

--
Michael Winter
M.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #6
"Michael Winter" <M.******@bluey onder.co.invali d> wrote in message
news:op******** ******@news-text.blueyonder .co.uk...
....
In addition to what Randy said, you should be aware that the SCRIPT
element doesn't support an id attribute under any version of HTML or
XHTML. This has two implications:

1) You can't write valid HTML of any kind (unless you use your own DTD)
2) Strictly conforming browsers shouldn't return a SCRIPT element that has
a matching id.


What about setting .src on document.script s[#]?
Will this also not work in Netscape, etc.?

Csaba Gabor
Jul 23 '05 #7
On Sun, 2 May 2004 13:10:14 +0200, Csaba Gabor <ne**@CsabaGabo r.com> wrote:
"Michael Winter" <M.******@bluey onder.co.invali d> wrote in message
news:op******** ******@news-text.blueyonder .co.uk...
...
In addition to what Randy said, you should be aware that the SCRIPT
element doesn't support an id attribute under any version of HTML or
XHTML. This has two implications:

1) You can't write valid HTML of any kind (unless you use your own DTD)
2) Strictly conforming browsers shouldn't return a SCRIPT element that
has a matching id.


What about setting .src on document.script s[#]?
Will this also not work in Netscape, etc.?


I shouldn't think so. The scripts collection is a Microsoft-ism, though
Opera supports it too. The latest version of Mozilla (1.8a) doesn't, so I
doubt Netscape will.

There's nothing wrong with using getElementsByTa gName() to achieve the
same effect, but Mozilla still isn't dynamic enough to load the new
script. It won't be the only one.

Mike

--
Michael Winter
M.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #8
Michael Winter wrote:
On Sun, 2 May 2004 13:10:14 +0200, Csaba Gabor <ne**@CsabaGabo r.com> wrote:
"Michael Winter" <M.******@bluey onder.co.invali d> wrote in message
news:op******** ******@news-text.blueyonder .co.uk...
...
In addition to what Randy said, you should be aware that the SCRIPT
element doesn't support an id attribute under any version of HTML or
XHTML. This has two implications:

1) You can't write valid HTML of any kind (unless you use your own DTD)
2) Strictly conforming browsers shouldn't return a SCRIPT element
that has a matching id.

What about setting .src on document.script s[#]?
Will this also not work in Netscape, etc.?


IE and Opera7 only, at the moment.

I shouldn't think so. The scripts collection is a Microsoft-ism, though
Opera supports it too. The latest version of Mozilla (1.8a) doesn't, so
I doubt Netscape will.
No, Netscape/Mozilla don't support changing the .src attribute (It
changes it, just doesn't load the .js file).

There's nothing wrong with using getElementsByTa gName() to achieve the
same effect, but Mozilla still isn't dynamic enough to load the new
script. It won't be the only one.


www.hikksworld.com/loadJSFiles/index.html

Shows where it can/cant be dynamically loaded, and what method is used
to do it with. Mozilla can dynamically load a .js file via createElement.

While the chart does not show it (I removed it), dynamically loading can
be achieved (on a PC anyway) in NN4.xx by opening a layer, writing a
script tag to it, then closing it.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq/
Jul 23 '05 #9

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

Similar topics

47
3756
by: mihai | last post by:
What does the standard say about those two? Is any assurance that the use of STL is thread safe? Have a nice day, Mihai.
16
8510
by: Robert Zurer | last post by:
Can anyone suggest the best book or part of a book on this subject. I'm looking for an in-depth treatment with examples in C# TIA Robert Zurer robert@zurer.com
5
2141
by: sarge | last post by:
I would like to know how to perform simple multithreading. I had created a simple form to test out if I was multithreading properly, but got buggy results. Sometime the whole thig would lock up when I got two threads going at the same time. What I have is two text boxes (textBox1 and textBox2) and four buttons(cmdStartThread1, cmdStartThread2, cmdStopThread1, cmdStopThread2)
9
2465
by: tommy | last post by:
hi, i have found a example for multithreading and asp.net http://www.fawcette.com/vsm/2002_11/magazine/features/chester/ i want to speed up my website ... if my website is starting, they should build a database-connection and send a few sqls
2
2312
by: Rich | last post by:
Hello, I have set up a multithreading routine in a Test VB.net proj, and it appears to be working OK in debug mode and I am not using synchronization. Multithreading is a new thing for me, and I just wanted to ask if I am missing anything based on the following scenario. My test app pulls data from a large external data source which has a table-like structure (but not rdbms - more
55
3330
by: Sam | last post by:
Hi, I have a serious issue using multithreading. A sample application showing my issue can be downloaded here: http://graphicsxp.free.fr/WindowsApplication11.zip The problem is that I need to call operations on Controls from a delegate, otherwise it does not work. However each time I've done an operation, I must update the progressbar and progresslabel, but this cannot be done in the delegate as it does not work.
5
2488
by: sandy82 | last post by:
Whats actuallly multithreading is ... and how threading and multithreading differ . Can any1 guide how multithreading is used on the Web .. i mean a practical scenario in which u use multithreading online using C# .
2
2267
by: Pradnya Patil | last post by:
hi , I am trying to draw ' html div-tag ' on the screen which will resemble a rectangle through vb.net code. I want it to be drawn faster...so I introduced multithreading using Threadpool. I divided the complete drawing into 3 parts..1st will be done by main thread and other two are done in these procedures - <1LongTimeTask <2LongTimeTask2 I have invoked the threads using below method. **************
7
16314
by: Ray | last post by:
Hello, Greetings! I'm looking for a solid C++ multithreading book. Can you recommend one? I don't think I've seen a multithreading C++ book that everybody thinks is good (like Effective C++ or Exceptional C++, for example). Platform-specific (e.g.: Win32, POSIX) is OK, as long as it's good :) Thank you, Ray
0
9643
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
10319
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
9947
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
8971
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
6737
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();...
0
5380
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...
1
4046
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
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2877
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.