473,395 Members | 1,458 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Finding the Host name on a particular window?

Hi,
I have a web application that operates on several windows. Each window
is named win_1, win_2, win_3,... . When I quit a session, I usually
loop through all the windows and close one by one. So far so good
until my client wants to surf on 1 particular window and doesn't want
that window to close when a I quit a session.
I had something in mind:
find the window url through "window.location.host" or something (I'd
save it as a global variable) and when I loop through my windows to
quit one by one, I thought I'd compare their host and if it is not
equal, I leave it open. I'm using the following codes at the moment:
_________________________
for($i=2;$i<=$window_number;$i++) {
$str = "if (window.parent.name != 'win_'".$i."') {window.open
('','win_'".$i."').close();}";
echo $str;
}
.....
echo "if (window.parent.name != 'win_1'){window.parent.close();}";
_________________________

Suppose win_3 has url "www.google.com", how can I retrieve the host
name of win_3? Is it possible? Is there any easy way without having
recourse to major changes? I appreciate any suggestions.
Kind regards
Bils
Jul 17 '05 #1
7 2270
Bilal wrote:
Hi,
I have a web application that operates on several windows. Each window
is named win_1, win_2, win_3,... . When I quit a session, I usually
loop through all the windows and close one by one. So far so good
until my client wants to surf on 1 particular window and doesn't want
that window to close when a I quit a session.
I had something in mind:
find the window url through "window.location.host" or something (I'd
save it as a global variable) and when I loop through my windows to
quit one by one, I thought I'd compare their host and if it is not
equal, I leave it open. I'm using the following codes at the moment:
_________________________
for($i=2;$i<=$window_number;$i++) {
$str = "if (window.parent.name != 'win_'".$i."') {window.open
('','win_'".$i."').close();}";
echo $str;
}
....
echo "if (window.parent.name != 'win_1'){window.parent.close();}";
_________________________

Suppose win_3 has url "www.google.com", how can I retrieve the host
name of win_3? Is it possible? Is there any easy way without having
recourse to major changes? I appreciate any suggestions.
Kind regards
Bils


Well, window.location.href will give you the URL of the page that is
displayed in the given window. So I suppose you could substring search
it, e.g:

if (window.location.href.indexOf('www.myhost.com') >= 0) {
// ...close window...
}

But, without further knowing what you want to do, I find the notion of a
multi-window web application rather ill-conceived. Are you sure you need
multiple windows and if so, couldn't you just use frames?

-Rico
Jul 17 '05 #2
Bilal wrote:
Hi,
I have a web application that operates on several windows. Each window
is named win_1, win_2, win_3,... . When I quit a session, I usually
loop through all the windows and close one by one. So far so good
until my client wants to surf on 1 particular window and doesn't want
that window to close when a I quit a session.
I had something in mind:
find the window url through "window.location.host" or something (I'd
save it as a global variable) and when I loop through my windows to
quit one by one, I thought I'd compare their host and if it is not
equal, I leave it open. I'm using the following codes at the moment:
_________________________
for($i=2;$i<=$window_number;$i++) {
$str = "if (window.parent.name != 'win_'".$i."') {window.open
('','win_'".$i."').close();}";
echo $str;
}
.....
echo "if (window.parent.name != 'win_1'){window.parent.close();}";
_________________________

Suppose win_3 has url "www.google.com", how can I retrieve the host
name of win_3?
You can't, unles win_3's URL is in your domain. Its a cross domain
security issue.
Is it possible?
Fortunately, no.
Is there any easy way without having recourse to major changes?
Not really.
I appreciate any suggestions.


Determine why you need 3+ windows open for your app to work, and then
work backwards and make it work within one window.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/
Jul 17 '05 #3
Rico Huijbers wrote:

<--snip-->


Well, window.location.href will give you the URL of the page that is
displayed in the given window. So I suppose you could substring search
it, e.g:

if (window.location.href.indexOf('www.myhost.com') >= 0) {
// ...close window...
}


That will work, if and only if, its in the same domain as the page
calling it. Otherwise, its a cross-domain security issue.

But, location.hostname is what the OP's after.


--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/
Jul 17 '05 #4
Bilal wrote:
Suppose win_3 has url "www.google.com", how can I retrieve the host
name of win_3? Is it possible?


No. Javascript security prohibits you from seeing anything about a window
which is not in the same domain as the one the code is running in. If you
try to get the href of a window which is at google.com, you'll get a
run-time error. You can trap this if you'd like, and continue on to the next
window.

--
Matt Kruse
Javascript Toolbox: http://www.mattkruse.com/javascript/
Jul 17 '05 #5
Rico Huijbers wrote:

Bilal wrote:
Hi,
I have a web application that operates on several windows. Each window
is named win_1, win_2, win_3,... . When I quit a session, I usually
loop through all the windows and close one by one. So far so good
until my client wants to surf on 1 particular window and doesn't want
that window to close when a I quit a session.

But, without further knowing what you want to do, I find the notion of a
multi-window web application rather ill-conceived.
That's good advice. Most people don't like web sites opening up a bunch
of new windows.
Are you sure you need
multiple windows and if so, couldn't you just use frames?

Ugh. Frames are not the solution to anything. The application should
move naturally from content page to content page as needed.


Brian Rodenborn
Jul 17 '05 #6
Default User wrote:
Ugh. Frames are not the solution to anything. The application should
move naturally from content page to content page as needed.


That's fine in most situations, but not always the best solution :)

--
Matt Kruse
Javascript Toolbox: http://www.mattkruse.com/javascript/
Jul 17 '05 #7
"Randy Webb" <hi************@aol.com> wrote in message
news:yJ********************@comcast.com...
Bilal wrote:
Hi,
I have a web application that operates on several windows. Each window
is named win_1, win_2, win_3,... . When I quit a session, I usually
loop through all the windows and close one by one. So far so good
until my client wants to surf on 1 particular window and doesn't want
that window to close when a I quit a session.
I had something in mind:
find the window url through "window.location.host" or something (I'd
save it as a global variable) and when I loop through my windows to
quit one by one, I thought I'd compare their host and if it is not
equal, I leave it open. I'm using the following codes at the moment:
_________________________
for($i=2;$i<=$window_number;$i++) {
$str = "if (window.parent.name != 'win_'".$i."') {window.open
('','win_'".$i."').close();}";
echo $str;
}
.....
echo "if (window.parent.name != 'win_1'){window.parent.close();}";
_________________________

Suppose win_3 has url "www.google.com", how can I retrieve the host
name of win_3?


You can't, unles win_3's URL is in your domain. Its a cross domain
security issue.


But for the same reason close() won't on that window either. Thus the stated
problem doesn't actually exist--not in Internet Explorer anyway.
Jul 17 '05 #8

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

Similar topics

2
by: Steve | last post by:
Hi, I have a very long string, someting like: DISPLAY=localhost:0.0,FORT_BUFFERED=true, F_ERROPT1=271\,271\,2\,1\,2\,2\,2\,2,G03BASIS=/opt/g03b05/g03/basis,...
7
by: Bennett Haselton | last post by:
Is there any way to find a string representing an object's class, which will work in Internet Explorer 6? "typeof" doesn't work -- it returns "object" for all objects: x =...
7
by: Bilal | last post by:
Hi, I have a web application that operates on several windows. Each window is named win_1, win_2, win_3,... . When I quit a session, I usually loop through all the windows and close one by one. So...
4
by: David Virgil Hobbs | last post by:
My web host inserts banner ads into my html pages. The javascript in these banner ads interferes with the onload triggered javascript functions in my pages. Whether I trigger my javascript...
7
by: George Hester | last post by:
Please take a look at this google artcle: http://groups.google.com/groups?hl=en&lr=&frame=right&th=55d6f4b50f5f9382&seekm=411f370d%241%40olaf.komtel.net#link9 The op was having trouble with...
8
by: Jason Bell | last post by:
Give the following custom attribute: public class WidgetEventAttribute : System.Attribute { protected Cegui.EventHandler mEventHandler = null; public WidgetEventAttribute( string...
2
by: Jeff S | last post by:
What are my options if I want to host hundreds of sites on one IIS server (like Internet presence providers do); such that site1.com, site2.com, site3.com... site278.com... are all hosted on the...
4
by: cpptutor2000 | last post by:
Could some C guru help me please? I am using the following program to open a SSH connection to a remote host and eventually run a program on that remote host. #include <stdio.h> #include...
9
by: stevewy | last post by:
I am trying to write a function that will test all the checkboxes in a particular group of a form (it's a questionnaire), see whether more than three of them are ticked, and display a message if...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...
0
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...
0
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...

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.