By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,747 Members | 1,782 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,747 IT Pros & Developers. It's quick & easy.

Finding the Host name on a particular window?

P: n/a
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 23 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
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 23 '05 #2

P: n/a
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 23 '05 #3

P: n/a
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 23 '05 #4

P: n/a
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 23 '05 #5

P: n/a
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 23 '05 #6

P: n/a
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 23 '05 #7

P: n/a
"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 23 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.