window.open not working in IE

我是研究僧i 提交于 2020-01-10 11:52:11

问题


Apparently, this call to window.open is not valid under Internet Explorer. The Javascript code on my site is not running, I would assume it is due to that error.

The line it tells me the error is on, is the call to window.open, apparently an argument is not valid there.

$('.objeto').click( 
        function() {
            var center   = 'height=380,width=900,top='+((screen.width - 900)/2)+',left='+((screen.height - 380)/2);
            var address = $(this).attr('id');
            window.open (address,'Ver articulo', config=center); 
        }
    );

The site runs fine under both Google Chrome, and Firefox.


回答1:


In IE, you can't have spaces in your second variable (the new window's name).

Try:

window.open (address,'Ver_articulo', config=center); 



回答2:


Also worth re-iterating that IE9 (and possibly below) doesn't like hyphens ('-') in the window name (2nd parameter).

I know one of the comments mentioned this, but it's a bit buried - and it's one tip that just solved an issue for me.




回答3:


I'm not sure what config is, you just need:

window.open (address,'VerArticulo', center);

Keep in mind though, it looks like your id attribute is invalid to get the effect here, you probably want to use something different, e.g. data-href="urlHere" on the element, if it's not an anchor already.




回答4:


even thou it's kind a late with answer for OP, but for someone else stumbling across this post it might help:

Had exactly same problem as OP after trying to use "window.open" method. It turns out that Chrome is ok with original href tag with URL in it where IE seems to get confused with that. After removing href from link worked spot on.

CODE SAMPLE:

$(document).ready(function () 
{
    $('a[rel^="external"]').each(function () 
    {
        var externalLink = $(this);
        var externalLinkValue = externalLink.attr("href");
        externalLink.unbind('click');
        externalLink.removeAttr("href");

        externalLink.click(function (event)
        {
            event.preventDefault();
            followExtrenalLink = window.open(externalLinkValue,'_blank');
        });

        externalLink.hover(function ()
        {
            externalLink.css('cursor', 'pointer');
        });

    });


来源:https://stackoverflow.com/questions/3662531/window-open-not-working-in-ie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!