Discuss Window.open does not work in IE? in the JavaScript Development forum on Dev Shed. Window.open does not work in IE? JavaScript Development forum discussing JavaScript and DHTML, AJAX, and issues such as coding cross-browser JavaScript.
But yet, even though FF works (of course) IE does not. It says 'Object Expected'. WTF Does that even MEAN? There are no arguments. How can it be expecting anything?
__________________ Bugs that go away by themselves come back by themselves
Beware - your loyalty will not be rewarded
Posts: 2,179
Time spent in forums: 2 Weeks 2 Days 15 h 44 m 6 sec
Reputation Power: 57
It would be beneficial to use onclick over the javascript prefix to
the href of the anchor. May not necessarily fix your object expected error...
Edit:
Just a thought, the space after the comma in the properties
list being passed through the function may possibly be the
error that's being raised.
Edit:
Posted without readily checking for errors, see derelicts post
below... haha thanks d!
Code:
function pop(url,wtitle,wprop){
if (!window.open){ return; }
if (!win){ var win= window.open(url,wtitle,wprop); }
if (win && win.focus){ win.focus(); }
}
Posts: 1,337
Time spent in forums: 2 Weeks 6 Days 8 h 35 m 8 sec
Reputation Power: 1036
this could also be because your function returns nothing. if you use the onclick and return false, then you should be in good shape. if you use the javascript: prefix, try wrapping the function call in a void() call:
javascript:void(window_test_IE());
void() tells IE that nothing is coming, so don't expect anything.
otherwise IE wants to take some action as a part of the link click. if your function returned a URL, I believe that URL would be loaded. if you return 'false' some versions of IE load a blank page saying 'false' (same for 'true').
the better solution, as mentioned by jsKid, is to run it as an onclick, and make sure your function returns false. then what the URL says doesn't matter... a good formation for compatability would be to follow jsKid's example (except, sorry jsKid, you needed to put your onclick on the link, not the image... I don't think images have .href properties )... I added some slight modifications...
Javascript Code:
Original
- Javascript Code
function pop(url,wtitle,wprop){
if(!window.open){return; }// get out now if we can't do this basic function
// I killed the if(win), since win was a local var this was a meaningless check
var win= window.open(url,wtitle,wprop);
// next line important in case you open multiple with the same 'wtitle'
// to make sure the window is reused and refocused.
if(win && win.focus){ win.focus(); }
returnfalse; // I do this here so the onclick is easier to read (for me anyway)
this way, you put as much info in the original link as possible, and make the javascript function mirror this functionality (by calling the link's written parameters with 'this'). to be truly inobtrusive, we'd want to assign the onclick separately so that the link doesn't have an inline handler (I can show you how to do this too if you want). so now, without JS, the link still clicks, still opens a new window, and still loads relevant content. in fact, the only difference is that the JS function allows use of the 'props' var to make modifications to the layout of the popped window. this style should work like a champ in all browsers. good luck!
P.S. - note that jsKid's version still didn't return anything; he forced it to return false in the onclick by returning !pop(), which is in some ways preferable, since !anything (except false) is false, turning a null function into false. but on the other hand, it'll turn a false-returning function true, which might not do exactly what you'd like... so I just force the false in the function call itself so I can return it directly. really just a matter of preference.
__________________
"Human history becomes more and more a race between education and catastrophe." (H.G. Wells) "Giving me a new idea is like handing a cretin a loaded gun, but I do thank you anyhow, bang, bang." (Philip K. D!ck)
Last edited by derelict : August 11th, 2008 at 02:33 PM.
Reason: highlight your syntax, dummy
Posts: 1,303
Time spent in forums: 1 Month 1 Week 1 Day 7 h 48 m 58 sec
Reputation Power: 784
Thank you both for your suggestions, they were both illuminating and very helpful. Now I do see where I can make some changes and improvements.
One thing that was causing issues was the parameter for the window 'title', in my original code I was using a title such as: 'Ioforge Design Portfolio'. Now for some strange unknown reason javascript does not like spaces, and when by accident I removed those spaces the window launched just fine.
This does not explain the whole issue with my code, but it was another thing to be aware of. I will try out these different solutions when I am able, and let you guys know if I have any issues.
Posts: 1,337
Time spent in forums: 2 Weeks 6 Days 8 h 35 m 8 sec
Reputation Power: 1036
ok, gotcha....
that 'title' isn't a title at all -- it's the 'name' you give to that window instance... you use that 'name' if you want to re-use the same window again in the future. It is utterly invisible to the end user.
like most variable 'names', it doesn't like spaces. I bet you'd probably have problems with asterisks, ampersands, and starting the name with dashes or parens too.
to use a new window every time, use the word 'new' (or is it '_new' ?) -- I haven't had to spawn new windows in so long I kind of forget....