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
Add a ment  | 

4 Answers 4

Reset to default 6

You 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