/    Sign up×
Community /Pin to ProfileBookmark

Can’t open new window

Every reference I can find online tells me to use window.open(url, name, etc), but in both firefox 3.6 and IE 8, the current window redirects to the url, rather than a new window opening. What am I doing wrong?

Ed

to post a comment
JavaScript

12 Comments(s)

Copy linkTweet thisAlerts:
@toicontienMar 18.2012 — If the window name is "_blank" then it opens in a new window every time. If it is anything else, it will open in the window you are currently in, save for a few other standard names. Can we see your code?

You should also know that browser settings can affect how windows open up. If a Firefox user, for example, has preferences set to always open new windows in a new tab, then the options for setting the window size, position, and display options might be ignored. On top of that, users might have a pop up blocker set. When the pop up blocker in the browser is invoked, the window.open method returns a null value, rather than a reference to the new window object.
Copy linkTweet thisAlerts:
@Ed_AddisauthorMar 18.2012 — Thanks for prompt reply. I tried using "_blank" for the name, but it still just redirects the current window.

In an html div:

<img src="SDL_Trados_Studio_2011_landscape_narrow.gif" height="50px" width="70px" alt="I'm using SDL Trados Studio 2011" onclick=popup(); />

and in the script section:

function popup()
{
window.open("http://www.translationzone.com/", "_blank","toolbar=no,location=no,directories=no");
}


Thanks in anticipation.

Ed
Copy linkTweet thisAlerts:
@toicontienMar 18.2012 — Are you getting a JavaScript error? Search for browser preferences affecting how windows open.
Copy linkTweet thisAlerts:
@Ed_AddisauthorMar 18.2012 — No errors at all - it's just as though I wanted to use the current window! In Firefox I have 'Open new windows in a new tab instead' checked, but it doesn't. Unchecking that makes no difference BTW.

Ed
Copy linkTweet thisAlerts:
@toicontienMar 19.2012 — I'm wondering if the lack of quotes around the value for the onclick attribute is the culprit. This code works for me:
[CODE]<!DOCTYPE HTML>
<html>
<head>
<title>Testing IMG onclick</title>
</head>
<body>
<img src="http://www.webdeveloper.com/forum/images/webdev-logo2.gif" alt="Web Developer Forums" onclick="popup();" />
<script type="text/javascript">
function popup()
{
window.open("http://www.webdeveloper.com/forum/", "_blank","toolbar=no,location=no,directories=no");
}
</script>
</body>
</html>[/CODE]


I'm using Firefox 11.0 on Mac OS.
Copy linkTweet thisAlerts:
@nap0leonMar 19.2012 — Works for me in IE8 on Win XP with or without the quotes (you should add the quotes though).

I don't have a FF 3.6.

It must be something in your settings...
Copy linkTweet thisAlerts:
@Ed_AddisauthorMar 19.2012 — No, inserting the quotes makes no difference. I didn't expect it to, because it's getting to the function OK. It's just the window.open bit that's not behaving correctly.
Copy linkTweet thisAlerts:
@Ed_AddisauthorMar 19.2012 — Works for me in IE8 on Win XP with or without the quotes (you should add the quotes though).

I don't have a FF 3.6.

It must be something in your settings...[/QUOTE]


Can't think what though - can you? Popups are not blocked ...
Copy linkTweet thisAlerts:
@nap0leonMar 19.2012 — Are you using a standard installation or an employer provided one?

Do other pop-ups work from other sites?

Save toicontien's code to your desktop as "test.html" and open the page in your IE8. Acknowledge the 'do you want to run active x' yellow bar thingy, and click the webdeveloper.com image. Are you getting a new window in this scenario?
Copy linkTweet thisAlerts:
@Ed_AddisauthorMar 19.2012 — Yes! - that opens a new window. Bizarre! OK, I need to chase down what the difference(s) is/are. I'll post again when I've got news.

Many thanks

Ed
Copy linkTweet thisAlerts:
@Ed_AddisauthorMar 19.2012 — Many apologies to you for wasting your time! I am an idiot!

My page consists of layers - a background image, and some html, with an area map based on the image. I found that clicking the areas wouldn't work because the html divs were on top, so I resolved it by mapping the areas onto a transparent image in a third layer on top.

You probably know what I'm going to say now - I had the javascript call in the html layer, rather than the top-level area map, which just had an href attribute.

All working OK now.

Thanks and sorry!

Ed
Copy linkTweet thisAlerts:
@auntniniMar 19.2012 — Here are two scripts to open pop-up windows. Note the window is given a "quoted name" and the "features string" is also quoted. You reference special _blank _new _top _parent window names as value of attribute TARGET=_blank.

The second "myopen" script worked fine for years, but now loses focus. The "mypop" does not lose focus. See http://www.gerigeans.com for "myopen" and http://www.chanit.com http://www.josephdenaro.com or http://www.auntnini.com/sites/index.html for "mypop" examples.

Seems that HTML5 will not support "features" of POP windows.

<i>
</i>/*in BODY
&lt;a href="#nogo" onclick="loadpage('../things/___.jpg')"&gt;TEXT&lt;/a&gt;*/

// JavaScript Document
var mypop=null;
function loadpage(url) {
if ((!mypop) || (mypop.close)) {
mypop = window.open (url, 'mypop', 'width=400px,height=375px,toolbar=0,resizable=1,screenx=0,left=20,screeny=0,top=20');
} else { mypop.document.location.href=url; }
mypop.focus(); return true;
}

==========================
/*in &lt;BODY&gt;
&lt;a href="javascript:myopen{'http://www,auntnii.com')"&gt;auntini&lt;/a&gt;*/
// JavaScript Document
// separate window for link

// CG215 separate window for link
function myopen(url)
{ window.open (url, 'links', 'toolbar=0,location=1,directories=0,status=0,menubar=0,scrollbars=auto,resizable=yes,dependent=yes,width=400,height=400'); window.blur();
}
var links; //to avoid "undefined" message
// JavaScript Unleashed's onUnload event handler
function clean() {
if (links != null) { links.close() };
}
×

Success!

Help @Ed_Addis spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...