script to open a new window

J

Jackmac

Hi all,

Hopefully an easy one for someone.

I'm trying to set up a link on my web pages which will allow me to open a
new window of a specific size. Got that to work without a problem. The
difficulty I have is that when you close the new window you've opened,
instead of having the page you cliked from, you see a page with... [object]
on it.

The page concerned is:

http://www.independentproducts.co.uk/test.htm

Any ideas anyone please?

TIA

Jackmac
 
J

Jonathan N. Little

Jackmac said:
Hi all,

Hopefully an easy one for someone.

I'm trying to set up a link on my web pages which will allow me to open a
new window of a specific size. Got that to work without a problem. The
difficulty I have is that when you close the new window you've opened,
instead of having the page you cliked from, you see a page with... [object]
on it.

The page concerned is:

http://www.independentproducts.co.uk/test.htm

Any ideas anyone please?

TIA

Jackmac
That's because window.open() return a reference to the new window which
to put in the href of the link.

<a href="javascript:foobar();">

is a bad idea, what happens if the user has javascript disabled?

better:


JavaScript:
function popup(url){
var newwin=window.open(url,'bob','WIDTH=320,HEIGHT=195');
return false; //so if javascript IS enabled prevents link on page
}


HTML:
<a href='http://www.wedgwood-group.com/'
onclick="return popup('http://www.wedgwood-group.com/')">
Click to download
</a>

If user has javascript disabled then the your download will be in main
window, else in the popup.
 
?

=?ISO-8859-1?Q?G=E9rard_Talbot?=

Jackmac a écrit :
Hi all,

Hopefully an easy one for someone.

I'm trying to set up a link on my web pages which will allow me to open a
new window of a specific size. Got that to work without a problem. The
difficulty I have is that when you close the new window you've opened,
instead of having the page you cliked from, you see a page with... [object]
on it.

The page concerned is:

http://www.independentproducts.co.uk/test.htm

Any ideas anyone please?

Everything you need:
http://developer.mozilla.org/en/docs/DOM:window.open

Gérard
 
?

=?ISO-8859-1?Q?G=E9rard_Talbot?=

Jonathan N. Little a écrit :
Jackmac said:
Hi all,

Hopefully an easy one for someone.

I'm trying to set up a link on my web pages which will allow me to
open a new window of a specific size. Got that to work without a
problem. The difficulty I have is that when you close the new window
you've opened, instead of having the page you cliked from, you see a
page with... [object] on it.

The page concerned is:

http://www.independentproducts.co.uk/test.htm

Any ideas anyone please?

TIA

Jackmac
That's because window.open() return a reference to the new window which
to put in the href of the link.

<a href="javascript:foobar();">

is a bad idea, what happens if the user has javascript disabled?

better:


JavaScript:
function popup(url){
var newwin=window.open(url,'bob','WIDTH=320,HEIGHT=195');
return false; //so if javascript IS enabled prevents link on page
}

If the window is already opened, then the user will still be clicking on
the link and the secondary window will not be brought up on top. This is
a very frequent and major usability problem with secondary window and
your code does not address this issue.

http://developer.mozilla.org/en/docs/DOM:window.open#Best_practices

HTML:
<a href='http://www.wedgwood-group.com/'
onclick="return popup('http://www.wedgwood-group.com/')">
Click to download
</a>

The popup will be non-resizable and will not render scrollbar(s) if
content overflows requested window dimensions; in both cases, this is
not user friendly and is not usable.

Also, if javascript is disabled, then the link will not be loaded in the
"bob" secondary window. Your code creates 2 sorts of behavior depending
on javascript support enabled/disabled.

http://developer.mozilla.org/en/docs/DOM:window.open#Always_use_the_target_attribute

Gérard
 
J

Jonathan N. Little

Gérard Talbot said:
Jonathan N. Little a écrit :
Jackmac said:
Hi all,

Hopefully an easy one for someone.

I'm trying to set up a link on my web pages which will allow me to
open a new window of a specific size. Got that to work without a
problem. The difficulty I have is that when you close the new window
you've opened, instead of having the page you cliked from, you see a
page with... [object] on it.

The page concerned is:

http://www.independentproducts.co.uk/test.htm

Any ideas anyone please?

TIA

Jackmac
That's because window.open() return a reference to the new window
which to put in the href of the link.

<a href="javascript:foobar();">

is a bad idea, what happens if the user has javascript disabled?

better:


JavaScript:
function popup(url){
var newwin=window.open(url,'bob','WIDTH=320,HEIGHT=195');
return false; //so if javascript IS enabled prevents link on page
}

If the window is already opened, then the user will still be clicking on
the link and the secondary window will not be brought up on top. This is
a very frequent and major usability problem with secondary window and
your code does not address this issue.

You are correct, however my intention was not to create a complete
solution for him but to illustrate where his trouble lay:

<a href='javascript:window.open('www.wedgwood-group.com/'...

would return a window object when clicked, destroying the calling window.

Yes adding focus to new window would help, better yet, don't do a popup
at all(many here would advocate that).



http://developer.mozilla.org/en/docs/DOM:window.open#Best_practices




The popup will be non-resizable and will not render scrollbar(s) if
content overflows requested window dimensions; in both cases, this is
not user friendly and is not usable.

That OP choice not mine, as said just addressing his problem/
Also, if javascript is disabled, then the link will not be loaded in the
"bob" secondary window. Your code creates 2 sorts of behavior depending
on javascript support enabled/disabled.

http://developer.mozilla.org/en/docs/DOM:window.open#Always_use_the_target_attribute

Yep your could add 'target="bob"' to link so javascript disable browsers
will open new window, and then DOCTYPE will be 4.01 transitional too,
right? ;-)
 
N

Neredbojias

With neither quill nor qualm, Jackmac quothed:
Hi all,

Hopefully an easy one for someone.

I'm trying to set up a link on my web pages which will allow me to open a
new window of a specific size. Got that to work without a problem. The
difficulty I have is that when you close the new window you've opened,
instead of having the page you cliked from, you see a page with... [object]
on it.

The page concerned is:

http://www.independentproducts.co.uk/test.htm

Any ideas anyone please?

TIA

Jackmac

Bah, 404!
 
S

SpaceGirl

Jonathan said:
Jackmac said:
Hi all,

Hopefully an easy one for someone.

I'm trying to set up a link on my web pages which will allow me to
open a new window of a specific size. Got that to work without a
problem. The difficulty I have is that when you close the new window
you've opened, instead of having the page you cliked from, you see a
page with... [object] on it.

The page concerned is:

http://www.independentproducts.co.uk/test.htm

Any ideas anyone please?

TIA

Jackmac
That's because window.open() return a reference to the new window which
to put in the href of the link.

<a href="javascript:foobar();">

is a bad idea, what happens if the user has javascript disabled?

better:


JavaScript:
function popup(url){
var newwin=window.open(url,'bob','WIDTH=320,HEIGHT=195');
return false; //so if javascript IS enabled prevents link on page
}


HTML:
<a href='http://www.wedgwood-group.com/'
onclick="return popup('http://www.wedgwood-group.com/')">
Click to download
</a>

If user has javascript disabled then the your download will be in main
window, else in the popup.

You should never *EVER* place javascript in the href property of an <a>
tag! Gawd.


<a href="mypage.html" onclick="popup('mypage.html'); return true;"
target="_blank"> ...

This way, the window will popup even if the user has javascript turned
off. In all major browsers the onclick even will take presidence over
the href="". This means if the user clicks with JS turned on they get a
nice (ahem) popup. If they have JS turned off, they just get a regular
window opening like any other href, but in a new browser instance.

Also, if writing popup code, always remember to add something like...

if (mywindow) { mywindow.focus(); }

^-checks window exists
^- brings the window to the front

....after the popup code. This forces the new window to come in front of
all other windows. The prevents a commong error seen with popups; the
popup has already been opened by the user but it now BEHIND the current
browser window and they have clicked for the popup again... it updates,
but because it's behind the current window you cant see it! Browsers
alway re-used named browser windows, so you wont get a new popup each
time unless the user has closed the popup window. THe focus trick gets
around that.

--


x theSpaceGirl (miranda)

# lead designer @ http://www.dhnewmedia.com #
# remove NO SPAM to email, or use form on website #
# this post (c) Miranda Thomas 2005
# explicitly no permission given to Forum4Designers
# to duplicate this post.
 
S

SpaceGirl

Jonathan said:
Gérard Talbot said:
Jonathan N. Little a écrit :
Jackmac wrote:

Hi all,

Hopefully an easy one for someone.

I'm trying to set up a link on my web pages which will allow me to
open a new window of a specific size. Got that to work without a
problem. The difficulty I have is that when you close the new
window you've opened, instead of having the page you cliked from,
you see a page with... [object] on it.

The page concerned is:

http://www.independentproducts.co.uk/test.htm

Any ideas anyone please?

TIA

Jackmac

That's because window.open() return a reference to the new window
which to put in the href of the link.

<a href="javascript:foobar();">

is a bad idea, what happens if the user has javascript disabled?

better:


JavaScript:
function popup(url){
var newwin=window.open(url,'bob','WIDTH=320,HEIGHT=195');
return false; //so if javascript IS enabled prevents link on page
}

If the window is already opened, then the user will still be clicking
on the link and the secondary window will not be brought up on top.
This is a very frequent and major usability problem with secondary
window and your code does not address this issue.


You are correct, however my intention was not to create a complete
solution for him but to illustrate where his trouble lay:

<a href='javascript:window.open('www.wedgwood-group.com/'...

would return a window object when clicked, destroying the calling window.

Yes adding focus to new window would help, better yet, don't do a popup
at all(many here would advocate that).



http://developer.mozilla.org/en/docs/DOM:window.open#Best_practices





The popup will be non-resizable and will not render scrollbar(s) if
content overflows requested window dimensions; in both cases, this is
not user friendly and is not usable.


That OP choice not mine, as said just addressing his problem/
Also, if javascript is disabled, then the link will not be loaded in
the "bob" secondary window. Your code creates 2 sorts of behavior
depending on javascript support enabled/disabled.

http://developer.mozilla.org/en/docs/DOM:window.open#Always_use_the_target_attribute



Yep your could add 'target="bob"' to link so javascript disable browsers
will open new window, and then DOCTYPE will be 4.01 transitional too,
right? ;-)


oops sorry

--


x theSpaceGirl (miranda)

# lead designer @ http://www.dhnewmedia.com #
# remove NO SPAM to email, or use form on website #
# this post (c) Miranda Thomas 2005
# explicitly no permission given to Forum4Designers
# to duplicate this post.
 
J

Jonathan N. Little

JDS said:
Shouldn't that be "return false"?

I would think so, else if JavaScript is enabled both the popup will load
AND the main page will load 'mypage.html'. You want it to return false
so that if JavaScript is enabled the main page link will be ignored but
if JavaScript is disabled the onclick event will be ignored and the
fall back will be that 'mypage.html' loads in the main window.
 
N

Neredbojias

With neither quill nor qualm, Jonathan N. Little quothed:
I would think so, else if JavaScript is enabled both the popup will load
AND the main page will load 'mypage.html'. You want it to return false
so that if JavaScript is enabled the main page link will be ignored but
if JavaScript is disabled the onclick event will be ignored and the
fall back will be that 'mypage.html' loads in the main window.

What if javascript is enabled but popups are disabled?
 
J

Jonathan N. Little

Neredbojias said:
With neither quill nor qualm, Jonathan N. Little quothed:




What if javascript is enabled but popups are disabled?

You're screwed! ;-)
That's a good reason NOT to use a popup right?
 
N

Neredbojias

With neither quill nor qualm, Jonathan N. Little quothed:
I would think so, else if JavaScript is enabled both the popup will load
AND the main page will load 'mypage.html'. You want it to return false
so that if JavaScript is enabled the main page link will be ignored but
if JavaScript is disabled the onclick event will be ignored and the
fall back will be that 'mypage.html' loads in the main window.

Ah, shit, once again I accidently deleted a reply, in this case yours.
Anyway, I said:

And you said:
You're screwed.

Actually, there is a way to do it which involves using "return true".

<a href="NerbsBigOne.html" onclick="if (window.open)
{ var nwin=window.open
(this.href,mywin,'toolbar=no,location=no,directories=no,status=no,menuba
r=no,scrollbars=no,resizable=no,width=8400,height=2200');
return false; } else { return true; }">The Human Monolith</a>
 
J

Jonathan N. Little

Neredbojias said:
With neither quill nor qualm, Jonathan N. Little quothed:




Ah, shit, once again I accidently deleted a reply, in this case yours.
Anyway, I said:


Aw, I'm crushed! :-D

Can't you just start a fresh with a new reply window, with all good
quothed material restored, or something as CTRL-Z to undelete the
'fat-finger' error?
And you said:




Actually, there is a way to do it which involves using "return true".

<a href="NerbsBigOne.html" onclick="if (window.open)
{ var nwin=window.open
(this.href,mywin,'toolbar=no,location=no,directories=no,status=no,menuba
r=no,scrollbars=no,resizable=no,width=8400,height=2200');
return false; } else { return true; }">The Human Monolith</a>

Hmmm, interesting, (referencing the code--my door doesn't swing that way!)
 
N

Neredbojias

With neither quill nor qualm, Jonathan N. Little quothed:
Aw, I'm crushed! :-D

Can't you just start a fresh with a new reply window, with all good
quothed material restored, or something as CTRL-Z to undelete the
'fat-finger' error?

I've tried. The only way I can recover the lost message is to
unsubscribe, then re-subscribe and re-download as new the last xxx
messages (-which, of course, loses all the "as read" formatting, etc.)
Hmmm, interesting, (referencing the code--my door doesn't swing that way!)

Um, no referencing was intended *that* way. Big boy.
 
T

Toby Inkster

JDS said:
Shouldn't that be "return false"?

I like:

<script type="text/javascript">
function popup (u,t)
{ return !window.open(u,t,'options'); }
</script>

<a href="mypage.html" target="mytarget"
onclick="return popup(this.href,this.target);">
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top