开发者

Open page in window of specific size

开发者 https://www.devze.com 2023-03-20 07:12 出处:网络
The following Javascript opens a window as required in IE8, FF4 and Safari 5.0.5 but not in Opera or Chrome.

The following Javascript opens a window as required in IE8, FF4 and Safari 5.0.5 but not in Opera or Chrome.

function setWindowSize(){

    var window_height = 600;
    var window_width = 600;

    window.resizeTo(window_width, window_height);
}

I would like a jQuery script that does the same, and hopefully does so in bo开发者_StackOverflow社区th Opera and Chrome.

Should not be too difficult, but it's got me beaten.


i think this is what you seeking for:

function popitup(url) {
    newwindow=window.open(url,'name','height=200,width=150');
    if (window.focus) {newwindow.focus()}
    return false;
}

EDITED: sorry it seems i got you wrong, take a look at this link: other forum


is this what you are looking for? this window resizes after 3 seconds: http://jsfiddle.net/mescalito2345/9yeBJ/

<html>
    <head>
        <script type="text/javascript">
            function openAndResizeWin()
            {
                myRef = window.open('','mywin','left=20,top=20,width=10,height=10,toolbar=1,resizable=0');
                var html = '<html><head><title>Print Your Recipe</title></head><body>Hola!</body></html>';
                myRef.document.open();
                myRef.document.write(html);
                setTimeout("myRef.resizeBy(500,500);",3000);
                myRef.focus();
                myRef.document.close();
            }
        </script>
    </head>
    <body>

        <input type="button" onclick="openAndResizeWin()" value="Open New Window" />
    </body>
</html> 


Looks like an open Chrome issue to me.

I'd suggest a workaround, but:

  1. I can't think of one;
  2. Resizing people's windows is incredibly annoying. Please don't do it. Please.

(Also, your code resizes the current window; it doesn't open a new one.)


Just thought I'd throw this up since I made this today. Made a jQuery Extension that basically converts the dreary task of writing window.open into jQuery syntax usage, meaning, making a popup window with default sizes like you want is as easy as:

$.winOpen('http://www.somesite.com', { height: 600, width: 600 });

or

$.winOpen({ url: 'http://www.somesite.com', height: 600, width: 600 });

And if assigned to a variable and you wanted to re-size it later you could:

var bob = $.winOpen('http://www.somesite.com');
// some time later
bob.resizeTo(600,600);

Also, it adds an array to your document data, so if it was the 2nd window you opened you could do like:

// 0 index array, so 1 would be the 2nd one
$(document).data('winList')[1].resizeTo(600,600);

So far tested in Chrome, IE, Safari, and FF with 0 errors, don't have opera installed yet. If you're in Chrome and think it doesnt work, look in upper right of your browser in right side of address bar, you may have pop-ups disabled.

Find Extension in JS area of this jsFiddle between /* - extension begins - */ and /* - extension ends - */

FYI, this extension also includes (as I needed to make them) two other funcs known as $.joinObj() and $.matchUrl()

  • $.joinObj(object, string) Function to simply take an object literal (i think that's what they are called) like { key1: 'val1', key2: 'val2' } and turn it into a string with a separator between each key/value pair. I thought there was a way to do this in jQuery, but couldn't find func for some reason.
  • $.matchUrl(string) Function that returns an object of a parsed url via the .match function of javascript. The object includes a key named valid that can be used to determine if the url is an url and not just a misplaced string.
0

精彩评论

暂无评论...
验证码 换一张
取 消