473,796 Members | 2,652 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

broad search for an object known to exist

I'm doing some work with various different Learning Management Systems
(LMS) and they each expose an object called "API". The problem is I
can't know beforehand how the user may decide to configure the LMS.

The LMS might open my page in a new window, in a frame, in a frame in a
new window... From my page I'm doing this search:

var fGetAPI = function(){
var numOfTries, lwindow, theAPI, i, j;
numOfTries = 20; // an arbitrary number
lwindow = window;
// Start by looking for the API in the current window
theAPI = lwindow.API;
if (!theAPI) {
for (i = 0; i < numOfTries; i++) {
while (!theAPI && lwindow.parent && lwindow.parent != lwindow) {
lwindow = lwindow.parent;
theAPI = lwindow.API;
if (!theAPI && lwindow.frames. length) {
for (j = 0; j < lwindow.frames. length; j++) {
theAPI = lwindow.frames[i].API;
if (theAPI) break;
}
}
}
if (!theAPI && lwindow.opener && !lwindow.opener .closed) {
lwindow = lwindow.opener;
theAPI = lwindow.API;
if (!theAPI && lwindow.frames. length) {
for (j = 0; j < lwindow.frames. length; j++) {
theAPI = lwindow.frames[i].API;
if (theAPI) break;
}
}
}
if (theAPI) break;
}
// if the API could not been found alert
if (!theAPI) {
theAPI = null;
alert("Unable to find API.");
} else alert("FOUND"); // for testing
}
return theAPI;
};
var locAPI = fGetAPI();

When I look at my code I can't help feeling that there must be a better
way to look through all possible windows.

Andrew Poulos-=
Jul 22 '08 #1
1 1065
Andrew Poulos wrote:
I'm doing some work with various different Learning Management Systems
(LMS) and they each expose an object called "API". The problem is I
can't know beforehand how the user may decide to configure the LMS.

The LMS might open my page in a new window, in a frame, in a frame in a
new window... From my page I'm doing this search:

var fGetAPI = function(){
var numOfTries, lwindow, theAPI, i, j;
numOfTries = 20; // an arbitrary number
lwindow = window;
// Start by looking for the API in the current window
theAPI = lwindow.API;
if (!theAPI) {
for (i = 0; i < numOfTries; i++) {
^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^
This is nonsense. Either the parent frameset or opener window is loaded or
it is not. If they are not loaded, the frame in which your script runs is
likely not to be loaded either. Anyhow, repeating something a limited
number of times in a tight loop is never likely to cover the issue reliably.
[...]
When I look at my code I can't help feeling that there must be a better
way to look through all possible windows.
There is. You might want to add recursion to your frame search. It would
also appear to be prudent to put this part of the search in a general method
that can be passed a Window object reference. And you must guard against
running into a reference loop, i.e. you need to create a list (an array) of
objects traversed so far and do not recurse if the object is in that list.
PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
Jul 22 '08 #2

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

Similar topics

6
2465
by: lawrence | last post by:
How dangerous or stupid is it for an object to have a reference to the object which contains it? If I have a class called $controllerForAll which has an arrray of all the objects that exist, what happens if one of those objects, when it is created, takes a reference to the object that contains it? Do bad things happen? class McShow {
0
5771
by: Phil Powell | last post by:
The table already has a fulltext index and from there I can use the MySQL fulltext search query to get results as well as the relevancy score. The problem I have is that MySQL has a default setting whereby the minimum amount of characters is 4 for a search. Being that we're government and full of TLA (three-letter acronyms), that is not practical, and furthermore, the app I'm building must be fully portable, so having MySQL tweaked...
106
5617
by: A | last post by:
Hi, I have always been taught to use an inialization list for initialising data members of a class. I realize that initialsizing primitives and pointers use an inialization list is exactly the same as an assignment, but for class types it has a different effect - it calls the copy constructor. My question is when to not use an initalisation list for initialising data members of a class?
0
3667
by: todd | last post by:
here is a search tool SP I wrote. How many times have you wanted to search all your Stored procs or views (in a database) for a keyword but couldn't!? Well now you can! THis can makes life a lot easier for developers. Would you email me and let me know which part of the world my code is running in?
0
1469
by: Anurag | last post by:
Hi, I understand that the dbm cfg parameter "DISCOVER" controls whether Search or Known discovery is applicable. Additionally, Search discovery provides a superset of Known discovery. I completely understand the scenario where SEARCH is applicable and where KNOWN is applicable. My question is very basic: >From a server's perspective, what extra is being done at the server to support SEARCH discovery? Are some extra proceeses / threads...
0
1567
by: Sushil Srivastava | last post by:
Hi Guys, I have developed a utility that provide a smart MSDN knowledge base search both off-line and on-line. I have describe more in detail below why I decided to write this utility (one reason is just for fun). Please let me know if you need this utility. Thanks Sushil
0
1756
by: tony | last post by:
Hello! I have one solution file that consist of three project. One project that build the exe file called A One project that build a user control dll. In this user control we have a class called B One project that build a class library dll. In this class library we have a class called C In the user control project I have a project reference to the class library.
73
4510
by: Water Cooler v2 | last post by:
I am new to PHP, just one day new. But I am otherwise a seasoned programmer on many other languages like C, VB 6, C#, VB.NET, Win32 platform and have some tiny bit experience in MFC, C++, Python. All the tutorials I read so far about PHP contain procedural examples. I haven't yet come accross a tutorial on the object oriented PHP. Could someone point me to one?
2
2662
by: slizorn | last post by:
hi guys, i need to make a tree traversal algorithm that would help me search the tree.. creating a method to search a tree to find the position of node and to return its pointer value basically i need to read in a text file... shown below H H,E,L E,B,F B,A,C A,null,null
0
9673
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
10449
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
10217
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
10168
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
10003
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
7546
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
5440
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
5568
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2924
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.