[Javascript] [JavaScript List] getElementsByClass probs
Lee Underwood
leeu at cfl.rr.com
Tue Jul 11 08:10:39 CDT 2006
(Courtesy of Jeremy Keith)
Place this in the external file:
function doPopups() {
if (!document.getElementsByTagName) return false;
var links=document.getElementsByTagName("a");
for (var i=0; i < links.length; i++) {
if (links[i].className.match("popup")) {
links[i].onclick=function() {
// Below - to open a full-sized window, just use:
window.open(this.href);
window.open(this.href, "", "top=40,left=40,width=500,height=625");
return false;
}
}
}
}
window.onload=doPopups;
Then place a link to it in the head:
<script type="text/javascript" src="doPopups"></script>
Then place this on each link you want to popup:
class="popup"
Lee
On 7/11/2006 05:59 AM, XtiaN wrote:
........................................................
>hi guys, i've problem here.. i want to make pop up window from my a
>href links using unobtrusive js.
>but it doesn't work...
>
>code in my html
><head>
><script type="text/javascript">
>addLoadEvent(function() {
>findBT2('btnym','/member/includes/popupym.html','200','100');
>findBT2('btnmsn','/member/includes/popupmsn.html','200','100');
>}
></script>
></head>
>....
><a href="#" class="btnym">link</a>
><a href="#" class="btnmsn">link</a>
>...
>
>external js:
>
>function addLoadEvent(func) {
> var oldonload = window.onload;
> if (typeof window.onload != 'function') {
> window.onload = func;
> } else {
> window.onload = function() {
> if (oldonload) {
> oldonload();
> }
> func();
> }
> }
>}
>
>//dustindiaz
>function getElementsByClass(searchClass,node,tag) {
> var classElements = new Array();
> if ( node == null )
> node = document;
> if ( tag == null )
> tag = '*';
> var els = node.getElementsByTagName(tag);
> var elsLen = els.length;
> var pattern = new RegExp("(^|\s)"+searchClass+"(\s|$)");
> for (i = 0, j = 0; i < elsLen; i++) {
> if ( pattern.test(els[i].className) ) {
> classElements[j] = els[i];
> j++;
> }
> }
> return classElements;
>}
>
>function findBT2(btnClass,what,width,height){
> var btn = getElementsByClass(btnClass,document,'*');
> //alert(btn);
> btn.onclick = function() {
> window.open(what, 'title', 'width='+width+',height='+height+'');
> return(false);
> }
>}
>_______________________________________________
........................................................
More information about the Javascript
mailing list