简体   繁体   中英

Open link in popup window

I might be tired but I just can't figure out what the problem is. What I'm trying to do is open a link in a popup window. I got this code below working before but I removed it.

<a href="#" onclick="window.open('http://google.com','popup','width=600,height=700,scrollbars=yes,resizable=yes,toolbar=no,directories=no,location=no,menubar=no,status=no,left=50,top=0'); return false">About</a>

However, it stopped working now when I put it back. I even got it working on jsFiddle so I'm at lost on what to do. I'm assuming something must be blocking it from running?

The code is short and simple so I figured someone here might have an idea what could cause this.

EDIT: Sorry I should have thought of it. I guess I should sleep. Anyway here's a demo-website where I reproduced the problem http://testmycode.tumblr.com/ The problem is the "About" link, pressing it returns nothing.

The snippet you shared works when I append it to the page we are at, in Google Chrome. Which makes me wonder which browser you are having the trouble in. So I would encourage you to try the snippet you shared in Google Chrome, and if it works there then you will know it is a browser specific kind of bug, in which case I would try adding a semicolon after return false .

OK, it seems like somewhere in your code you have changed the window variable to a custom function. When you try to call window.open (more specifically, document.window.open ) , the method open simply doesn't exist in the function window , which causes it to throw an error.

Check this out:

在此处输入图片说明

You somewhere changed it to a function by doing document.window = ... .

It's MooTools 1.2.4 which changed it:

在此处输入图片说明


To fix it, simply using an EventListener and problem solved! (Inline codes are bad practice anyway.)

<a class="about">About</a>

$(".about")attr("href", "#").click(function(e){
    window.open(...);
    e.preventDefault();
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM