Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8243257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:27:15+00:00 2026-06-07T21:27:15+00:00

I have a webpage in which an element is clicked on and an image

  • 0

I have a webpage in which an element is clicked on and an image is obtained from the server using a JQuery post function and should be displayed in a new window which is resized to the image. The relevant Javascript function is as follows (where myImage is the returned image in base 64 format).

function showPicture(label) {
        var newWindow = window.open("", label,"scrollbars=0, toolbar=0");
        $.post( 'picture-view', { labelname: label },
        function(myImage) {
            newWindow.document.write("<img src='data:image/png;base64," + myImage + "'/>");
            newWindow.resizeTo(newWindow.document.getElementsByTagName("img")[0].width,     newWindow.document.getElementsByTagName("img")[0].height+newWindow.outerHeight-newWindow.innerHeight);
            newWindow.focus(); 

        }
    );          
}

There are three things which are causing me problems.

  1. The image is inserted into the new window with a white border which I cannot figure out how to remove.

  2. The term newWindow.outerHeight-newWindow.innerHeight is supposed to account for the toolbar etc. when resizing the window, but both are being output as zero.

  3. This last one has really been annoying me. If I put the line var newWindow = window.open("", label,"scrollbars=0, toolbar=0"); within the callback function which starts on line four then the new window is created too small and will not be resized by the resizeTo function.

Any advice or directions to further reading would be very helpful.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T21:27:17+00:00Added an answer on June 7, 2026 at 9:27 pm

    You’re using jQuery, so you could simplify this A LOT, but since you’re already using plain JS for so much, I just kept going with it.

    You should wait until the image is loaded before opening the new window, that way you can set the size to the same as the image, something like this:

    function showPicture(label) {
        $.post( 'picture-view', { labelname: label }, function(ImageSrc) {
           var myImage = new Image;
               myImage.src = "data:image/png;base64," + ImageSrc;
               myImage.style.border = 'none';
               myImage.style.outline = 'none';
               myImage.style.position = 'fixed';
               myImage.style.left = '0';
               myImage.style.top = '0';
               myImage.onload = function() {        
                   var newWindow = window.open("", label,"scrollbars=0, toolbar=0, width="+myImage.width+", height="+myImage.height);
                       newWindow.document.write(myImage.outerHTML);
              }​
        });
    }
    

    Here’s a FIDDLE showing how it’s done, with the base64 just added in the file as I did’nt have time to create some sort of fake Ajax function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have content on a webpage which is both sent from the server at
I have created a Webpage which will post as post method..not as get method.
I have an image on a webpage which is being dynamically generated by a
I have a webpage, on which I am using Ajax to replace different divs
I have a webpage with a form, which looks kinda like this: @using (Html.BeginForm(MyAction,
i have a jquery function which i want to convert to .live because i
I have a UIWebView which is loading a webpage. The webpage has a div-element
I have a div element which acts as a global contianer for my webpage,
I have an webpage which posts some data and then redirects to a page
Here's the situation I have a webpage which has one drop down called prefer.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.