Sorry to burst your bubble, but this script is partly broken in Opera as I had first suggested but I couldn’t see the pattern. From what I was told after asking around, it is a built in permissions thing that Opera is more strict about and other browsers seem not to be as strict. Set a popup link to open a page from a different domain and both the popup and the main window will go to the destination.
I don’t know JS so I don’t know if there is a fix. However, as long as you are creating popups from pages within your domain, you won’t see this problem.
Copy & paste the code below to embed this comment.
Nathan Cocks
As a person who consistantly searches news feeds from a variety of sources, some using popups others not, I generally open new windows to view information.
It is heartening to see people advocating pop up code that will allow me to do my traditional ‘open in new window’ actions on links that use javascript.
Nothing more frustrating than opening the new window, having it fail, shutting that window down and clicking on the link normally.
Copy & paste the code below to embed this comment.
michael schieben
Gulliver/Caio, some information i found concering event listeners and IE5/OS9 at http://developer.apple.com/internet/webcontent/eventmodels.html
“If you plan to support IE5/Mac, you can dismiss the attachEvent() and addEventListener() methods because IE5/Mac supports neither of these.”
There is only on way left to apply a function to an event (beside coding in the document structure):
element.onclick = myFunc;
I extended Caios listen function:
function listen(event, elem, func) {
elem = getElem(elem);
if (elem.addEventListener) // W3C DOM
elem.addEventListener(event,func,false);
else if (elem.attachEvent) // IE DOM
elem.attachEvent(‘on’+event, function(){ func(new W3CDOM_Event(elem)) } );
// for IE we use a …
else // IE5/OS9 elder browsers
eval(“elem.on” + event + “= func”);
}
The examples all work fine now.
Thanks a lot for your great article and the cclib.js!
michael, actually the thing (handling ie5/os9) is a bit more complicated than that: the function handling the event will expect an event object, but when a function is assigned to handle an event via “element.onevent = fn” it element itself will be passed as parameter to the function, so we must use the same wrapper we used for IE/win:
This was an excellent article, which demonstrated a lot of very usefull techniques, especially the listener model.
And, yes, I’m one of those users who usually opens up links in new windows and gets REALLY frustrated when some lame webdeveloper has javascript’ed their links.
Well, I came to this article hoping to find a way to stay XHTML 1.0 validated, but open offsite links in a new window (can’t be validated with target in your links) saddly, you can’t be validated with onclick in your links, either… anyone know of any other solutions?
Copy & paste the code below to embed this comment.
Ondrej Valek
Haven’t tried this way yet. I’m interested in what happens, when you click on this right-way-made popup link with popups banned in your browser (such as Mozilla or some commercial popup-blocking proxies for IE).
Does it open at least the normal href link?
In my opinion, popus should not be used, unless necessary, and should be announced in advance (with some icon like for those abroad-targeting links). For example, it’s nice to use popups for internet radios’ “Now playing” windows.
Due to a discussion in a recent post on Simon Willison’s blog (http://simon.incutio.com/archive/2004/05/26/addLoadEvent), I’ve updated “listen” in a more backwards compatible way, that may solve IE5/mac issues. Here’s the new code with a simple event test case: http://v2studio.com/k/code/newlisten.html
130 Reader Comments
Back to the Articlegulliver
>treat IE5/OS9 as an aging browser and let it fall back on the sub-optimal behavior that you describe…
Thanks, C. That’s sound advice and something I’m increasingly accepting.
Julian Rickards
Hi:
Sorry to burst your bubble, but this script is partly broken in Opera as I had first suggested but I couldn’t see the pattern. From what I was told after asking around, it is a built in permissions thing that Opera is more strict about and other browsers seem not to be as strict. Set a popup link to open a page from a different domain and both the popup and the main window will go to the destination.
I don’t know JS so I don’t know if there is a fix. However, as long as you are creating popups from pages within your domain, you won’t see this problem.
Nathan Cocks
As a person who consistantly searches news feeds from a variety of sources, some using popups others not, I generally open new windows to view information.
It is heartening to see people advocating pop up code that will allow me to do my traditional ‘open in new window’ actions on links that use javascript.
Nothing more frustrating than opening the new window, having it fail, shutting that window down and clicking on the link normally.
Here’s hoping everyone takes this up.
michael schieben
Gulliver/Caio, some information i found concering event listeners and IE5/OS9 at http://developer.apple.com/internet/webcontent/eventmodels.html
“If you plan to support IE5/Mac, you can dismiss the attachEvent() and addEventListener() methods because IE5/Mac supports neither of these.”
There is only on way left to apply a function to an event (beside coding in the document structure):
element.onclick = myFunc;
I extended Caios listen function:
function listen(event, elem, func) {
elem = getElem(elem);
if (elem.addEventListener) // W3C DOM
elem.addEventListener(event,func,false);
else if (elem.attachEvent) // IE DOM
elem.attachEvent(‘on’+event, function(){ func(new W3CDOM_Event(elem)) } );
// for IE we use a …
else // IE5/OS9 elder browsers
eval(“elem.on” + event + “= func”);
}
The examples all work fine now.
Thanks a lot for your great article and the cclib.js!
Caio Chassot
michael, actually the thing (handling ie5/os9) is a bit more complicated than that: the function handling the event will expect an event object, but when a function is assigned to handle an event via “element.onevent = fn” it element itself will be passed as parameter to the function, so we must use the same wrapper we used for IE/win:
elem[‘on’+event] = function(){ func(new W3CDOM_Event(elem)) }
(also see there’s no need to use eval)
Terry
This was an excellent article, which demonstrated a lot of very usefull techniques, especially the listener model.
And, yes, I’m one of those users who usually opens up links in new windows and gets REALLY frustrated when some lame webdeveloper has javascript’ed their links.
Thanks again
Terry
Kali
Well, I came to this article hoping to find a way to stay XHTML 1.0 validated, but open offsite links in a new window (can’t be validated with target in your links) saddly, you can’t be validated with onclick in your links, either… anyone know of any other solutions?
Ondrej Valek
Haven’t tried this way yet. I’m interested in what happens, when you click on this right-way-made popup link with popups banned in your browser (such as Mozilla or some commercial popup-blocking proxies for IE).
Does it open at least the normal href link?
In my opinion, popus should not be used, unless necessary, and should be announced in advance (with some icon like for those abroad-targeting links). For example, it’s nice to use popups for internet radios’ “Now playing” windows.
User just should now that it is a popup.
Caio Chassot
Kali, there’s a solution in the article that works without onclick, and the target attribute is completely optional.
Caio Chassot
Due to a discussion in a recent post on Simon Willison’s blog (http://simon.incutio.com/archive/2004/05/26/addLoadEvent), I’ve updated “listen” in a more backwards compatible way, that may solve IE5/mac issues. Here’s the new code with a simple event test case: http://v2studio.com/k/code/newlisten.html