开发者

How would use javascript to open an image in a separate window after I resize it?

This is the code that I have to re-size the image for me. What I don't know how to do is have the code open the image after it has been re-sized.

So what I wish for it to is is

  1. Resize the image(It 开发者_如何转开发is already doing this).
  2. Once image is re-sized, open it in a separate window

This is the code that re-sizes the image for me.

function resize(which, max) {
    var elem = document.getElementById(which);
      if (elem == undefined || elem == null) return false;
     if (max == undefined) max = 1024;
    if (elem.width > elem.height) {
      elem.width = max;  
     elem.height = 768;
    }
   }


That code does not actually resize the picture, it just changes how it is displayed. If the image is downloaded or opened in a separate window, it will be the dimensions of the original image. I don't think there is any way of modifying the image through JavaScript.

What you could do, though, is find a program that can do that for you and call that through an Ajax call. For example, I think the Gimp can handle that, and if you can call that from a PHP script, then you can call that PHP script through an Ajax call and display that. It's kind of a complicated solution but that's the best I can think of.


As tjameson pointed out, JavaScript doesn't really resize your image.

If you want to take this image to a new window, here is a way to do it:

var im = document.getElementsByTagName('img')[0];
var w = window.open("");
var b = w.document.body;
b.appendChild(im);

You can apply the resize function on this image if you want it displayed resized.


I appended the needed code to the initial resize function

    function resize(which, max) 
    {
        var elem = document.getElementById(which);
        if (elem == undefined || elem == null) return false;
        if (max == undefined) max = 1024;
        if (elem.width > elem.height) 
        {
            elem.width = max;  
            elem.height = 768;
        }
        var f = window.open("", "_blank", "height=500, width=600,toolbar=0, menubar=0, scrollbars=1, resizable=1,status=0, location=0, left=10, top=10");
        f.document.title = elem.alt;
        f.document.body.innerHTML += '<img src="'+elem.src+'" height="'+elem.height+'" width="'+elem.width+'" alt="'+elem.alt+'">';


}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜