admin管理员组文章数量:1312662
I hope my question is one that is simple to answer, but unfortunately I don't have a great knowledge of javascript. I've spend a good portion of the day Googling the issue and trying various workarounds, but nothing has worked adequately thus far.
I am running a very simple piece of JavaScript so that when an image is clicked a separate window opens. This will work in every other browser (including mobile) except for IE. Following is what I've included in my head tag -
<script type="text/javascript">
function open_win() {
window.open("music/player/song-of-my-soul.html", "_blank, _top", "toolbar=no, location=no, directories=no, status=no, menubar=mo, scrollbars=yes, resizable=no, toolbar=no, copyhistory=yes, width=240, height=400,");
}
</script>
I have then created a div with a background image and hover image, that when clicked should open the above page. Following is the line I have placed within the div -
a href="#" alt="Listen to Samples" title="Listen to Samples" class="play-link" onclick="open_win()">
This works fine in every other browser, but will not work in IE. I have tried several ways to reference the JavaScript in the head, but none of them will work.
The page that I'm testing this on can be seen at the following - .php# The 'Play' button in the center towards the bottom is the image that I have linked.
If anyone would have any ideas on how I might fix this I would be most grateful !
David
I hope my question is one that is simple to answer, but unfortunately I don't have a great knowledge of javascript. I've spend a good portion of the day Googling the issue and trying various workarounds, but nothing has worked adequately thus far.
I am running a very simple piece of JavaScript so that when an image is clicked a separate window opens. This will work in every other browser (including mobile) except for IE. Following is what I've included in my head tag -
<script type="text/javascript">
function open_win() {
window.open("music/player/song-of-my-soul.html", "_blank, _top", "toolbar=no, location=no, directories=no, status=no, menubar=mo, scrollbars=yes, resizable=no, toolbar=no, copyhistory=yes, width=240, height=400,");
}
</script>
I have then created a div with a background image and hover image, that when clicked should open the above page. Following is the line I have placed within the div -
a href="#" alt="Listen to Samples" title="Listen to Samples" class="play-link" onclick="open_win()">
This works fine in every other browser, but will not work in IE. I have tried several ways to reference the JavaScript in the head, but none of them will work.
The page that I'm testing this on can be seen at the following - http://www.christlikemusic./song-of-my-soul.php# The 'Play' button in the center towards the bottom is the image that I have linked.
If anyone would have any ideas on how I might fix this I would be most grateful !
David
Share Improve this question asked Sep 14, 2011 at 15:04 David O'BrienDavid O'Brien 11 silver badge1 bronze badge 2- In IE there are some javascript errors in the page, did you check what are they? – Arun P Johny Commented Sep 14, 2011 at 15:12
- check out stackoverflow./questions/710756/… – Tim B James Commented Sep 14, 2011 at 15:17
4 Answers
Reset to default 6You have a trailing ma in the windows options list:
[snip] ... copyhistory=yes, width=240, height=400,");
^--- here
IE is notoriously stubborn about trailing mas, and will regularly barf all over itself if it es within a few miles of one.
The window name can not have space.
So you need to change "_blank, _top"
to something else.
Try wrapping the window.open with the void function:
EDIT: You also had a trailing ma after the height
specification.
<script type="text/javascript">
function open_win() {
void(window.open("music/player/song-of-my-soul.html", "_blank, _top", "toolbar=no, location=no, directories=no, status=no, menubar=mo, scrollbars=yes, resizable=no, toolbar=no, copyhistory=yes, width=240, height=400"));
}
</script>
Here's a method that I created for opening child windows. You can use this if you'd like:
openChildWindowWithDimensions = function(url, width, height, showMenu, canResize, showScrollbars) {
var childWindow = window.open(url, "", "\"width=" + width + ",height=" + height + ",menubar=" + (showMenu ? "1" : "0") + ",scrollbars=" + (showScrollbars ? "1" : "0") + ",resizable=" + (canResize ? "1" : "0") + "\"");
if (childWindow){
childWindow.resizeTo(width, height); //IE9 bug
}
}
The problem is the second argument. Try
window.open("music/player/song-of-my-soul.html", "_blank", "toolbar=no, location=no, directories=no, status=no, menubar=mo, scrollbars=yes, resizable=no, toolbar=no, copyhistory=yes, width=240, height=400");
The second parameter is the name of the window to be opened. It has to be a valid name, in your case you have passed it as _blank, _top
which is not a valid name. It can be _blank
.
You can find more valid values here and IE definitions here.
If you are using a new IE version like IE8/IE9 then you can run the mand using the developer tool which es with IE and find that the window.open
is throwing an invalid argument
error.
本文标签: JavaScript Onclick windowopen will not work properly in IEStack Overflow
版权声明:本文标题:JavaScript Onclick window.open will not work properly in IE - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741904025a2404034.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论