How I did it
The extension is very easy, it executes a GET request to the xkcd website, gets the content of the index page and returns it. What I used to do, for a matter of simplicity, was getting the content, paste it in an hidden div, get the image of the comic of the day (through a getElementById call) and put it in a visible div.
The Problem
What one would expect is that the Google Chrome popup page of the extension notice the change of content and resize itself to fit the new content. But this doesn't happen. The popup page remains as small as it can get without styles, or of a fixed with/height if specified in the css file. I didn't wanted to have a fixed width/height as comics usually have not a fixed size (sometimes they are as small as a strip, sometimes they are quite big).
Since the popup extension doesn't resize, I though about resizing it using JavaScript:
var width = document.getElementById("comic").offsetWidth + 10; var height = document.getElementById("comic").offsetHeight + 10; //[...] document.body.style.width = ""+width; document.body.style.height = ""+height; document.getElementsByTagName("html")[0].style.width = ""+width; document.getElementsByTagName("html")[0].style.height = ""+height;
(notice that I get the width and the height of the image and add a small offset to make it visually finer). The fact is that this approach wasn't working either. When opening the extension, one would see it flicker: first a frame of the correct size, and then a resize to the default 10 by 10 pixel frame.
The Solution
The solution was quite simple, but without somebody mentioning it on StackOverflow I would be still stuck. The fact is that the popup of the Chrome Extensions don't resize if there is a hidden element in the HTML tree. That is, basically the whole page I was hiding was preventing me to resize the popup frame. So the solution is:
document.getElementById("hiddenDiv").innerHTML = "";
And that solved every problem. The frame now is the correct size and I can read every two/three days the new xkcd comic.
Hi,
ReplyDeleteI was having the same problem.
There is a simple solution to this too.
You need to add
to the beginning of your popup code. :)
Src: https://groups.google.com/a/chromium.org/forum/#!topic/chromium-extensions/AHPZo_yoNFg
Someone has already a solution for this one? .. I have been trying by using only one resizable textarea element in the popup...but, chrome doesn't resize the popup's height. However, it resizes the width.
ReplyDeleteLuxury watch replicas are quality rolex replica sale that are made to resemble their significantly more expensive designer counterparts at a fraction of the price. For example, the average rolex replica sale Submariner, an extremely popular luxury watch, will set you back anywhere, depending on the condition of the rolex replica and which model you choose. The Rolex Submariner diving watch was initiated at watches store during 2017 which happened to coincide with the growth of self contained below the surface breathing apparatus, called scuba. In the year of replica watches Rolex had a couple of editions of the Submariner. These quality timepieces offer those who can afford the real thing the opportunity to accessorize their outfits with beautiful watches that look and operate just like the real thing. Because rolex replica sale are so affordable, most can afford to purchase more than one, giving them the opportunity to try many different looks and styles.
ReplyDelete