Javascript: Onclick event not working in IE

13,680

The window.open() method expects all of those height, width, etc., parameters as a single string:

window.open('stream/index.html', 'LiveStream',
            'height=70,width=500,toolbar=no,menubar=no,scroolbars=no,resizable=no,location=no,directories=no,status=no');

According to MDN the window name and the string with the features should not contain blank space. I don't know why your existing code works in FF.

Most or all of your <a> variations should work, but of the ones you tried I'd suggest this one:

<a href="javascript:void(0)" onclick="streamwindow()">Listen Live</a>

Better, though, would be to set the href to the same URL as what the JS will open, so that the link will still work for users with JS disabled. For users with JS enabled you then return false from the onclick so that the default navigation doesn't occur as well as your onclick:

<a href="stream/index.html" onclick="streamwindow(); return false;">Listen Live</a>

If the above still doesn't work I'd suggest you temporarily replace the contents of your functions with a simple alert("In function x"); message to test if the functions are being called at all.

Share:
13,680
Guy TechnoBear Curtis
Author by

Guy TechnoBear Curtis

Updated on June 04, 2022

Comments

  • Guy TechnoBear Curtis
    Guy TechnoBear Curtis almost 2 years

    I have tried to google this to no avail and have tried multiple options. All of which work in firefox but none have worked in IE. I have 2 onclick events on one page and neither are working in IE. The javascript file for both events is called by:

    <script type="text/javascript" src="openwindow.js"></script>
    

    The first event is an anchor event which I started with as:

    <a href="" onclick="streamwindow()">Listen Live</a>
    

    then tried

    <a href="javascript:streamwindow()">Listen Live</a>
    

    then:

    <a href="javascript:void(0)" onclick="streamwindow()">Listen Live</a>
    

    then:

    <a href="javascript:openwindow.js" onclick="streamwindow()">Listen Live</a>
    

    then:

    <a onclick="javascript:streamwindow()">Listen Live</a>
    

    I think that is everything I have tried so far for that one. The other click event is called when the user clicks on an image. Again works fine in firefox as is but not in IE. Code for the second event is:

    <td width="450px" align="center">
    <p>Clip of The Day</p>
    <img id="image2" src="images/sound.jpg" onclick="clipwindow()" />
    </td>
    

    I have played with this one quite as much. The javascript file (openwindow.js) contains:

    function clipwindow()
    {
    window.open ('clipoftheday.html', 'Clip of the Day', 'height=200',
    'width=100', 'toolbar=no', 'menubar=no', 'scrollbars=no', 'resizable=no',
    'location=no', 'directories=no', 'status=no')
    }
    
    function streamwindow()
    {
    window.open ('stream/index.html', 'Live Stream', 'height=70', 'width=500', 'toolbar=no', 'menubar=no', 'scroolbars=no', 'resizable=no', 'location=no', 'directories=no', 'status=no')
    }
    

    Please help me with this. I look forward to hearing back from people.