#1
  1. Recovering Intellectual
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2006
    Location
    Orange County, CA
    Posts
    1,306
    Rep Power
    785

    Window.open does not work in IE?


    This is frustrating beyond all measure.

    I have an external JS file defined as such:

    Code:
    <!--
    
    function window_test_IE()
    {
    
    window.open('http://www.ioforge.com/', 'TEST', 'width=650, height=650');
    
    }
    
    //-->
    And I call said function as such:

    Code:
    <a href="javascript:window_test_IE()">
    <img src="URL/IMAGE" alt="ALT" class="thumb" />
    </a>
    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
  2. #2
  3. Application is what Divides Us
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Dec 2002
    Location
    Titusville, FL
    Posts
    2,179
    Rep Power
    58
    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(); }
    }
    Code:
    <a href='url' title=''><img src='url/img.extension' alt='ALT' class='thumb' onclick="return !pop(this.href,'','');" /></a>
    Last edited by jsKid; August 13th, 2008 at 01:04 AM.
    Download [ Fx | Op ] Validate [ Markup | Css ]
  4. #3
  5. garish grotesque gargoyle
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2006
    Location
    gracing gargantuan gothic gateways
    Posts
    1,337
    Rep Power
    1037
    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:
    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(); }
    	return false; // I do this here so the onclick is easier to read (for me anyway)
    }


    then update your call to...
    HTML Code:
     
    <a href="http://www.ioforge.com/" target="TEST" onclick="return pop(this.href, this.target, 'width=650,height=650');">
    <img src="URL/IMAGE" alt="ALT" class="thumb" />
    </a>


    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.
    Last edited by derelict; August 11th, 2008 at 02:33 PM. Reason: highlight your syntax, dummy

    "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)
  6. #4
  7. Recovering Intellectual
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2006
    Location
    Orange County, CA
    Posts
    1,306
    Rep Power
    785
    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.
    Bugs that go away by themselves come back by themselves
    Beware - your loyalty will not be rewarded
  8. #5
  9. garish grotesque gargoyle
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2006
    Location
    gracing gargantuan gothic gateways
    Posts
    1,337
    Rep Power
    1037
    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....

    HTH - derelict

    "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)
  10. #6
  11. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,127
    Rep Power
    4304
    Originally Posted by derelict
    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....
    '_blank' is used for that. An empty string might work too.

    http://developer.mozilla.org/en/docs....open#Examples

    Comments on this post

    • derelict agrees : mozilla and msdn say '_blank' which looks to have originally been a microsoft convention
    Last edited by Kravvitz; August 11th, 2008 at 05:16 PM.
    Spreading knowledge, one newbie at a time.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).

IMN logo majestic logo threadwatch logo seochat tools logo