admin管理员组文章数量:1426907
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.
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.
Share Improve this question asked Nov 1, 2011 at 20:26 Guy TechnoBear CurtisGuy TechnoBear Curtis 211 gold badge1 silver badge2 bronze badges 4- This may not solve your problem, but popup windows can be a bad choice these days since many browsers will default to disallow that feature. for IE, try holding ctrl + click to see if that bypasses the restriction that MAY be happening. If so, I would say your best bet is to use something like colorbox to load in the files on the page itself so no user can experience this problem... Of course, if I read your situation right, it looks like an audio or video clip that you may intend to stand alone so the user can continue browsing? – Kai Qing Commented Nov 1, 2011 at 20:31
- 2 You're calling "window.open()" incorrectly. All of the window option parameters are supposed to be jammed together in a single string, separated by mas. – Pointy Commented Nov 1, 2011 at 20:34
- Pointy has a better observation. look at this link... javascript-coder./window-popup/javascript-window-open.phtml – Kai Qing Commented Nov 1, 2011 at 20:35
- ok i changed the openwindow.js but it still does not work in IE. the status bar reads error on page when i try to trigger the events – Guy TechnoBear Curtis Commented Nov 1, 2011 at 20:45
2 Answers
Reset to default 1The 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.
Two problems:
The window name (for IE) must be a valid identifier, so "Live Stream" won't work. Try "Live_Stream" or "LiveStream" instead.
The window option parameters ("scrollable", "height", etc) need to all be bined into one string, separated by mas.
本文标签: htmlJavascript Onclick event not working in IEStack Overflow
版权声明:本文标题:html - Javascript: Onclick event not working in IE - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745487218a2660435.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论