onclick function works in IE6, not in FF1.5

Discussion in 'Javascript' started by Mike Scirocco, Apr 15, 2007.

  1. I use this function to detect an iframe button click. It works in IE6
    but not in FF 1.5.

    function setupbutton(){
    var myiframe=document.getElementById('ifrmEditCategory');
    var mybutton=myiframe.contentWindow.document.getElementById('btnClose')
    //alert('myiframe '+myiframe+' mybutton '+mybutton);
    mybutton.onclick=function() {btncloseclick()}
    }

    I call this after the iframe has been completely loaded, and make srue
    the code can find the btnClose with the alerts... objects are shown for
    both variables, so I'm sure it's finding the button.

    Is there a way to make this code more robust for different browser?

    Thanks,
    Mike
     
    Mike Scirocco, Apr 15, 2007
    #1
    1. Advertisements

  2. This works in IE 6 and FF 1.5:

    function setupbutton(){
    var myiframe=document.getElementById('ifrmEditCategory');
    var mybutton=myiframe.contentWindow.document.getElementById('btnClose');
    if (window.addEventListener) {
    mybutton.addEventListener('click', btncloseclick, true);
    }else if (window.attachEvent){
    mybutton.attachEvent('onclick',btncloseclick);
    }else{
    mybutton.onclick= btncloseclick();
    }
    }
     
    Mike Scirocco, Apr 15, 2007
    #2
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.