|
Posted by SpaceGirl on 10/07/05 01:01
Jonathan N. Little wrote:
> 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
> }
>
>
> 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.
[Back to original message]
|