I have been frustrated for years, when I go to open a link in a new window in a web browser (via a middle mouse click binding, in a half sensible browser on a half sensible platform), and it turns out to be a link to javascript:void(0). Or a link to the same page, because the target was "#" in the current directory. So I go back to the original page, and dutifully click on the link again to open it the way the webpage developer intended, and all it does is to open a popup that uses javascript... to open a new URL.
So I go ogle for an explanation of why some web developers have settled on using javascript:void(0) and "#" as the targets to their href links. And I discover posts like this, advocating the most complex of javascript for html code that should simply read
<a href="http://www.your_buddies_site.com"
target="_blank">Check out my buddies' site</a>
(Check out my buddies' site) followed by affirmations from people saying "thanks! That's going into my site straight away!". OK, this guy at least has a (bogus) justification for wanting to use javascript, but it was the best example of a class of methods I found when I wrote this originally (a month ago, and then forgot to make it public).
This post here says to use void(0) and why they advocate that - to tell the browser not to follow the URL once it's finished processing the javascript.
And then getting closer to a real solution is to return false from the onclick handler in order to tell the browser not to redirect to the top of the page in the case of using "#" in the href target. But why link to "#" at all? If you're just trying to open a webpage, let's obey the user when they ask to open the webpage in a new window or tab, and even better, let's keep working when they have turned off javascript. Just link to the page in question, instead of "#". The javascript will still be executed, and the "return false" will tell the browser to ignore the href target. If the javascript doesn't execute because the user asked for the page to be opened in a new window, then the target is still good.
The page that triggered my annoyance this time was a website where presumably they'd want to hire people who actually knew how to write webpages that didn't piss off their paying customers. Instead, their code looks like this:
<a href="Javascript:void(0);" onclick="window.open('/ups/ebm_pop.asp','p1',
'location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=550,height=180'
);">Extended Battery Modules (EBMs)</a> increase UPS battery runtime capability
So they've done it exactly wrong. I open the link in a new window, and the URL it opens is simply the very bland javascript:void(0); That doesn't make me want to buy anything.
I was actually looking at this lastnight, for a page on our intranet to display in frames, the fullsky camera along with a javascript clock (using nixie tubes as the digits :). Why implement a clock in javascript on a webpage? It's being displayed on an 8 bit x-terminal, with what appears to be no fonts whatsoever. "xclock -digital" runs, but as soon as I ask several versions linked against libfreetype and otherwise, to use a different font, it still uses the too small default font. You can't read the clock from across the room. You can however, read the nixie tube .gifs from across the room. And furthermore, I display local time, Queensland time (equivalent to non-DST time), UTC and Mean Julian Date, since all are relevant to us (the display linked above is a small part of the frameset ultimately displayed -- sorry, is behind access controls -- too computationally expensive on my own personal workstation; oh, and woe would be the external bandwidth). All displayed in a nice soothing retro nixie tube style, since soon all of the nixie tube displays will be removed from this building with the Telescope Control Computer upgrade (head computer dude is going to make himself a real nixie tube digital clock to satisfy all his nostalgia needs).
I wrote three different versions of the page, with different sizes of the skycam image, so the main browser window can be set to three different sizes, since for some of our instruments, the display also needs to accomodate various sized panels displaying instrument status. I don't want any toolbars, menubars or address bars taking screen space since this is just a status display - the person setting it up can always ctrl-N to get a new window if they need to. But I do want the user to be able to open a new window with the other choices for window-size, which would be a full browser window with toolbars etc (gives them a chance to get a normal browser window to do normal browsing on, but they really shouldn't be doing it on that machine). Note also, that this is for an intranet. This is a status display. It will be displayed on one machine, using a dedicated account, with a browser set up not to ignore all that crappy javascript stuff I usually turn off. I can afford to get away with more things than I would normally afford myself. I would not normally set window sizes for instance, but here, it is exactly what we want - and any changes I ever make to it will be tested explicitly on the one and only machine it is ever designed to display on. Don't assume you can blindly get away with it yourself, unless you control your viewers' browsers.
So the page with window size choices are given by code that sets the window size and which decorations are displayed:
<a href="aatxth-large.html" onClick="window.open('aatxth-large.html', '_blank',
'width=786,height=824,location=no,menubar=no,status=no,scrollbars=no,toolbar=no');
return false;">Large</a><br>
<a href="aatxth-medium.html" onClick="window.open('aatxth-medium.html', '_blank',
'width=734,height=788,location=no,menubar=no,status=no,scrollbars=no,toolbar=no');
return false;">Medium</a><br>
<a href="aatxth-small.html" onClick="window.open('aatxth-small.html', '_blank',
'width=553,height=646,location=no,menubar=no,status=no,scrollbars=no,toolbar=no');
return false;">Small</a><br>
Notice how the onclick handler will ask the browser to open a new window with "_blank"? I get my three window size choices and get a browser window without decorations (you can't rely on that of course -- the user may have disabled that in the browser). The onclick handler returns false to tell the browser not to do anything with this page, once the new window has been created. If the user opened a new page manually, they get exactly the same URL being opened in that, via the href target. If javascript was off, again, the main href target gets opened. You could add a target="_blank" to that too, if you wanted.
And to unconditionally open a new tab or window, each of those pages contains a link back to this choices page:
<a href=".." target="_blank">Other skycam sizes</a>
It just opens a new window with default decorations, etc. That's presumably what most of these "help" pages and tutorials *should* have been saying. |