Home > Archive > PHP Programming > May 2004 > Finding the Host name on a particular window?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
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
| |
| Rico Huijbers 2004-05-24, 12:32 pm |
| 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
| |
| Randy Webb 2004-05-24, 1:30 pm |
| 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/
| |
| Randy Webb 2004-05-24, 1:30 pm |
| 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/
| |
| Matt Kruse 2004-05-24, 1:30 pm |
| 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/
| |
| Default User 2004-05-24, 2:30 pm |
| Rico Huijbers wrote:
>
> Bilal wrote:
[color=darkred]
> 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
| |
| Matt Kruse 2004-05-24, 5:32 pm |
| 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/
| |
| Chung Leong 2004-05-24, 7:30 pm |
| "Randy Webb" <hikksnotathome@aol.com> wrote in message
news:yJmdnYCeJ55tvy_d4p2dnA@comcast.com...
> Bilal wrote:
>
> 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.
|
|
|
|
|