Search code examples
htmlmootools

open target _blank window with specific size with Mootools


how can I resize a window which is opened by a link with target_blank with Mootools?

Thank you

jsfiddle: http://jsfiddle.net/hxyTB/5/

<a href="http://www.golivewire.com/forums/img.cgi?i=168078" target="_blank">klick</a>

Solution

  • Try this:

    The script/function is plain javascript and I added the event handler with Mootools ( the click event handler you have on your fiddle looks like jQuery to me). Check the function's parameters and change as you need.

    Fiddle

    document.getElements('a.window').addEvent('click',function(e){
        e.stop();
        NewWindow(this.href,'pagename','350','500','no','center');
        return false
    });
    
    var win = null;
    function NewWindow(mypage, myname, w, h, scroll, pos) {
        if (pos == "center") {
            LeftPosition = (screen.width) ? (screen.width - w) / 2 : 350;
            TopPosition = (screen.height) ? (screen.height - h) / 2 : 500;
        } else {
            LeftPosition = 0;
            TopPosition = 20
        }
        settings = 'width=' + w + ',height=' + h + ',top=' + TopPosition + ',left=' + LeftPosition + ',scrollbars=' + scroll + ',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
        win = window.open(mypage, myname, settings);
    }
    
    • You can read more about window.open() at MDN to adjust details. In the code above for example there is no url bar, and no scroll bar.
    • I used Mootools's .getElements(), this will work for other <a> with same class. If you have just one element you can use Mootools's .getElement(), without "s".