I'm trying to design a site that makes use of
the window.open() javascript method by opening certain links in a new window with a specific pixel size and position onscreen, but Internet Explorer (with default security settings) blocks most attempts...Is there any way around this, to let IE know that its a legitimate site? Or does anyone know exactly what criteria IE looks at in determining popups?

All the pages opened are in the same site, under the same domain, and most of them are even served from the same directory. I just need to open them at a certain position on-screen, and have them be a certain size, and window.open() seems like the correct way to do this.

Dani AI

Generated

Short answer: Internet Explorer treats a window opened by script as a “popup” unless it was created directly as the immediate result of a user gesture (a click or keypress). Calls to open a new window from non-interactive contexts — page load, unload handlers, delayed timers, or other indirect script paths — are blocked by the Pop‑up Blocker. The official IE docs state that window.open must be invoked from a user‑initiated action and that calls from unload-type events are specifically affected. (learn.microsoft.com)

What that means for the thread: ’s observation that default IE blocks most attempts is expected behavior; it isn’t a site‑reputation flag you can flip from script. and are on the right track — making the new window open synchronously during a real click is the reliable approach. Adding the site to Trusted Sites / Local Intranet or the browser’s “allow pop-ups” list will bypass the blocker for that site, but that requires user or admin action (and has security tradeoffs). (learn.microsoft.com)

Quick, practical checklist and a debug test:

  • Verify whether a popup is being blocked by running a quick window.open from the console and seeing if it returns a Window object or null.
    window.open('about:blank','test','width=200,height=200')
  • Ensure window.open is executed synchronously inside the user gesture handler — avoid onload, onunload, setTimeout, or other indirect calls.
  • If you must preserve layout/position, open a simple page (via a user click) and have that page resize/reposition itself — or fall back to target=_blank with graceful degradation for users who block popups. Also avoid inline javascript: hrefs for accessibility and reliability. (learn.microsoft.com)

Bottom line: there’s no supported way to make IE treat a non‑user‑initiated script call as legitimate. The dependable solutions are: require a user click (synchronous), ask users to allow your site, or change the UI to avoid popups altogether. (learn.microsoft.com)

Recommended Answers

All 13 Replies

Using the target _blank attribute on a hyperlinked anchor tag is generally more likely to get past popup blockers...

That's not so good because you can't control the spawned window's size directly or open the new window automatically.

Some popup blockers would object to this kind of popup aswell O_O

Member Avatar for Member #119018

NO there is no way to do that. If there was, then every site would do it so their popups dont get blocked!

I'm going to have to agree with Dukane, I looked for information but it looks like all popup windows are blocked.

i just dont understand why microsoft can't make even a simple web browser that works :(

well, the solution ive come up with is to just use target="_blank" links, then resize and relocate the window as it loads. its pretty hacky, but its the only thing that works in IE under default security settings. plus it has a degree of degredation for when javascript is disabled altogether.

thanks all, i appreciate the advice!

thanks all, i appreciate the advice!

Thank you. I like your solution by the way. Its creative.

If I turn the popup blocker on, it's because I don't want popups.

have you tried this?

<script>

function openpage(){
//set this to the file of the page.html
var pagefile="YOUR PAGE HTML HERE"

if (document.all)
pagewindow=window.open(pagefile,"","width=445,height=250")
else
pagewindow=window.open(pagefile,"","width=445,height=250,scrollbars")
}
</script>

<a href="javascript:openpage()">OPEN PAGE CLICK HERE</a>

always better to give folk a choice when it comes to popups if possible imo. :D

Why not just put an anchor tagged link on the page. If I want the extra page, I will click it. I don't need bamboozlers popping up to attract me to the link.

Yep thats the idea, it only pops up if the link is clicked (see above)

Why not just put an anchor tagged link on the page. If I want the extra page, I will click it. I don't need bamboozlers popping up to attract me to the link.

you misunderstand the original issue, being that ie blocks any use of window.open(), even in a link. meaning the following is still blocked, and by the default explorer configuration, no less:

<a href="javascript:window.open('newpage.html',params)">

you misunderstand the original issue, being that ie blocks any use of window.open(), even in a link. meaning the following is still blocked, and by the default explorer configuration, no less:

<a href="javascript:window.open('newpage.html',params)">

Are you sure its not your browser settings or something? My example above works perfectly in IE.

Are you sure its not your browser settings or something? My example above works perfectly in IE.

:shrug: it didnt work for me and like 10 other people, all on default ie settings (not sure about ie7)

A "better way" to write:

<a href="javascript:window.open('newpage.html',params)">

is:

<a href="newpage.html" onclick="window.open('newpage.html',params); return false;">

That way it satisfies both users with and withought JavaScript support on their browser.
(winout JS you wont be able to control the window anyway)

Using href="javascript:(some code)" will also write the returned object to the document window. So you'll get a blank page with "[object]" written in it in IE and in FF you get "[object Window]".

You could wrap the javascript in void() like:

<a href="javascript:void(window.open('newpage.html',params));">

but thats just adding unnecessary code.

I've never had a problem with popup blockers blocking window.open() in an "onclick" event..
On non-interactive events.. like window.onload or setTimeout .. yes.

I've never tries javascript:window.open in the href attribute. Maybe thats handled differently. You should probably try the onclick method, as its more standard.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.