Bookmarklet to fit window to contents
-
- Posts: 196
- Joined: September 23rd, 2018, 11:07 am
Bookmarklet to fit window to contents
I was searching for a bookmarklet that is able to adjust the window size of the browser to the actual contents in the current webpage. I saw some bookmarklets that adjust the size to a given one, but no solution that is able to adjust to the size needed to show the current content in a compact way (without leaving unused space in the window). For example at https://www.20minutes.fr/ if you window's size is large you will see a large amount of unused space on the right and left, that you can avoid my manually resizing the window.
- ElTxolo
- Posts: 2811
- Joined: July 30th, 2007, 9:35 am
- Location: Localhost
Re: Bookmarklet to fit window to contents
user2018 wrote:I was searching for a bookmarklet that is able to adjust the window size of the browser to the actual contents in the current webpage. I saw some bookmarklets that adjust the size to a given one, but no solution that is able to adjust to the size needed to show the current content in a compact way (without leaving unused space in the window). For example at https://www.20minutes.fr/ if you window's size is large you will see a large amount of unused space on the right and left, that you can avoid my manually resizing the window.
Bookmarklet Fit to Width
Code: Select all
javascript:(function(){function%20t(f){a=d.createNodeIterator(d,1,f,false);while(a.nextNode()){}}var%20d=document;t(function(e){x=e.offsetLeft;l=e.offsetParent;while(l!=null){x+=l.offsetLeft;l=l.offsetParent}var%20w=d.documentElement.clientWidth-x;var%20s=e.style;if(s.marginLeft)w-=s.marginLeft;if(s.marginRight)w-=s.marginRight;if(s.paddingLeft)w-=s.paddingLeft;if(s.paddingRight)w-=s.paddingRight;if(s.borderSize)w-=s.borderSize;w-=d.defaultView.innerWidth-d.documentElement.offsetWidth;if(e.tagName=='IMG'){h=e.clientHeight*w/e.clientWidth;s.maxHeight=h}s.maxWidth=w+'px'})})();
- Before:
- After:
Cheers!!!
How to Ask Questions The Smart Way - How to Report Bugs Effectively
Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20240318 SeaMonkey/2.53.18.2
Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20240416 SeaMonkey/2.53.19
~
Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20240318 SeaMonkey/2.53.18.2
Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20240416 SeaMonkey/2.53.19
~
-
- Posts: 196
- Joined: September 23rd, 2018, 11:07 am
Re: Bookmarklet to fit window to contents
Thank you very much, that is an interesting approach. However, I was looking for the opposite kind of solution: instead of enlarging the content to fit the width of the window, I would like to adjust the width of the window according to the actual content.
- jscher2000
- Posts: 11767
- Joined: December 19th, 2004, 12:26 am
- Location: Silicon Valley, CA USA
- Contact:
Re: Bookmarklet to fit window to contents
There are some restrictions on scripts resizing windows in Firefox. Click the little box under Firefox for a compatibility note:
https://developer.mozilla.org/docs/Web/ ... patibility
https://developer.mozilla.org/docs/Web/ ... patibility
-
- Posts: 196
- Joined: September 23rd, 2018, 11:07 am
Re: Bookmarklet to fit window to contents
Thank you for the tip. Then I think that it could be possible if the bookmarklet opens the current tab again in a new window (with window.open) and then resizes it.
- ElTxolo
- Posts: 2811
- Joined: July 30th, 2007, 9:35 am
- Location: Localhost
Re: Bookmarklet to fit window to contents
Thank you very much ...
- You're welcome!!
How to Ask Questions The Smart Way - How to Report Bugs Effectively
Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20240318 SeaMonkey/2.53.18.2
Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20240416 SeaMonkey/2.53.19
~
Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20240318 SeaMonkey/2.53.18.2
Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20240416 SeaMonkey/2.53.19
~
- jscher2000
- Posts: 11767
- Joined: December 19th, 2004, 12:26 am
- Location: Silicon Valley, CA USA
- Contact:
Re: Bookmarklet to fit window to contents
I haven't tried that myself, but it sounds like it is worth a shot if that wouldn't a problem on that site.user2018 wrote:Thank you for the tip. Then I think that it could be possible if the bookmarklet opens the current tab again in a new window (with window.open) and then resizes it.
-
- Posts: 196
- Joined: September 23rd, 2018, 11:07 am
Re: Bookmarklet to fit window to contents
I found this, which works well even though it is not a bookmarklet:
resizemybrowser.com
I'm not sure if I am on the right path because even if I achieve transforming that idea into a bookmarklet then there is the issue of how could I determine the right width size for the given contents in the window. Any idea or suggestion is welcome.
resizemybrowser.com
I'm not sure if I am on the right path because even if I achieve transforming that idea into a bookmarklet then there is the issue of how could I determine the right width size for the given contents in the window. Any idea or suggestion is welcome.