Shortest syntax for preloading images in Javascript (in answer to a question by Wouterd yesterday):
for(i in ['larry.gif','moe.gif',
'curly.gif'])(new Image()).src=M[i];1. posted by Traumwind at 10:11 on August 02, 2001
that can be shortened:
for(i in M=['larry.gif','moe.gif','curly.gif'])(new Image()).src=M[i];
[] replaces the new Array constructor...
cool stuff, man!
for(i in M=['larry.gif','moe.gif','curly.gif'])(new Image()).src=M[i];
[] replaces the new Array constructor...
cool stuff, man!
2. posted by milov.nl,milo,milov at 14:09 on August 02, 2001
sweet!
add a comment
<a href="javascript:window.open('foo.html');">or this:
<a href="#" onclick="window.open('foo.html');">rather, use:
<a href="foo.html" onclick="window.open(this.href);return false;">benefits:
- statusbar still indicates where you're going
- non-js users (and search-engines) still end up at the correct page
- current page doesn't jump to top (faux-anchor '#' evil)
- shift- and right-click options still open the correct page
Update:
Apparently using
return false;in the href can mess up some browser's popup-blocking, so watch out if you care about that (haven't noticed it myself, but then again, I almost never use popups). [via]1. posted by Marza at 00:56 on August 14, 2001
2. posted by David at 11:16 on August 14, 2001
3. posted by pup at 17:18 on August 14, 2001
4. posted by Jim at 17:55 on December 28, 2001
5. posted by Joe Clark at 21:40 on December 30, 2001
6. posted by Norse at 21:57 on January 02, 2002
7. posted by charles at 22:39 on January 04, 2002
8. posted by matt at 18:01 on February 17, 2002
9. posted by zachariah at 06:42 on March 21, 2002
10. posted by Tim Scarfe at 21:39 on June 16, 2002
I don't like inline behaviour in the HTML element of my documents though, How about making it have a class of "pop", and then having a seperate script run through the document at the end picking up all the elements and assigning the events?
De-gradable coding, isn't it so cool :)
11. posted by kesor at 23:24 on August 31, 2002
I tried to expand text, like this :
<p>this is some text <a href="" onclick="moretext.style.display='inline'; return false;">more text</a></p>
<p id="moretext">this is some more text</p>
It works great in explorer, but doesnt work in opera and mozilla.
I guess its the return false that is not working.
12. posted by 127.0.0.1,me,sh0rtie at 13:13 on September 04, 2002
<a href="" onclick="document.getElementById('moretext').style.display='inline';return false">blah</a>
13. posted by 127.0.0.1,me,sh0rtie at 13:13 on September 04, 2002
<a href="" onclick="document.getElementById('moretext').style.display='inline';return false">blah</a>
14. posted by 127.0.0.1,me,sh0rtie at 13:13 on September 04, 2002
<a href="" onclick="document.getElementById('moretext').style.display='inline';return false">blah</a>
15. posted by 127.0.0.1,me,sh0rtie at 13:13 on September 04, 2002
<a href="" onclick="document.getElementById('moretext').style.display='inline';return false">blah</a>
16. posted by 127.0.0.1,me,sh0rtie at 13:13 on September 04, 2002
<a href="" onclick="document.getElementById('moretext').style.display='inline';return false">blah</a>
17. posted by 127.0.0.1,me,sh0rtie at 13:13 on September 04, 2002
<a href="" onclick="document.getElementById('moretext').style.display='inline';return false">blah</a>
18. posted by 127.0.0.1,me,sh0rtie at 13:13 on September 04, 2002
<a href="" onclick="document.getElementById('moretext').style.display='inline';return false">blah</a>
19. posted by 127.0.0.1,me,sh0rtie at 13:13 on September 04, 2002
<a href="" onclick="document.getElementById('moretext').style.display='inline';return false">blah</a>
20. posted by 127.0.0.1,me,sh0rtie at 13:16 on September 04, 2002
sorry about that , blame mozilla , i only hit submit once :/
21. posted by MidgetSniper at 01:13 on September 19, 2002
22. posted by xxx.lt,akello,Akello at 03:51 on December 23, 2002
23. posted by gfdh at 11:39 on February 20, 2003
24. posted by FitzChivalry at 13:13 on September 17, 2003
25. posted by yahoo.com,redjester,hadlock at 19:41 on October 12, 2003
26. posted by Gobalopper at 11:40 on November 02, 2003
<a href="yourlink.html" onclick="window.open(this.href,'blah','height=250,width=300,top=50,left=50,scrollbars=yes,titlebar=true'); return false;">link text</a>
27. posted by Ich at 15:44 on December 30, 2003
28. posted by nyexotic at 21:55 on January 29, 2004
29. posted by earl-ku at 13:41 on February 09, 2004
30. posted by Jay at 06:35 on March 10, 2004
31. posted by wooki at 21:38 on April 03, 2004
32. posted by fargo at 23:16 on May 11, 2004
33. posted by milov at 23:22 on May 11, 2004
34. posted by Symen at 09:07 on December 01, 2004
It works in my firefox, opera and ie. You must have made a typo..
But anyway, good article milovrs!
35. posted by sandra at 12:39 on July 01, 2005
36. posted by Joy at 01:41 on September 22, 2005
with frames? I have the <a href="offer.html".. in a frame and when i click it, offer.html is open in the self frame and not in a popup window.
37. posted by gmail.com,askubusku,seema at 12:28 on September 27, 2005
<p id="moretext">this is some more text</p>
It works great in explorer, but doesnt work in opera and mozilla.
I guess its the return false that is not working.
38. posted by Milo at 12:30 on September 27, 2005
onclick="document.getElementById('moretext').style.display='inline'; return false;"
This should work in IE, Mozilla and Opera.
39. posted by eapen at 21:59 on October 25, 2005
40. posted by mayglee at 08:02 on November 11, 2005
good page, thanx
41. posted by riccardo at 03:06 on November 12, 2005
42. posted by hotremoveforsendingmail.com,sager_svend,eSKape at 08:35 on February 09, 2006
I guess the only way to open links in another frame is to use targets. But target is okay, they are XHTML.. but not Strict. Maybe you are not using the right DTD? You are using framesets, so you should use XHTML Frameset.
As http://www.w3schools.com/tags/tag_a.asp say,
43. posted by hotremoveforsendingmail.com,sager_svend,eSKape at 08:37 on February 09, 2006
As url say, target is allowed in Transitional and Frameset, but not in Strict.
44. posted by yahoo.com,fuckthegovernment,Alex at 21:56 on February 26, 2006
<0><0>
..<>
((SWEET))
45. posted by RskpsVVMSlXGDP at 15:58 on June 05, 2008
46. posted by someOne at 16:57 on January 08, 2009
47. posted by Imu at 13:58 on November 10, 2009