Javascript resize page

hello - i have a page that has a dynamically sized div. it probably works fine about 99.5% of the time but occasionally it renders pretty strangely. the simple workaround is to ask people to resize the page and as soon as they grab the lower-right corner, everything is fine.

so, i am wondering about some jScript or jQ function that resizes the browser window a pixel or so, something people would not even notice is happening.

i tried a couple of ideas on jsfiddle but nothing seemed to work on chrome:
window.resizeTo(screen.width-1,screen.height-1)

a question like this would have been downvoted on SO so i am trying here instead.

I think this might be what you’re looking for, and make sure you call it once the page has been loaded and ready :

$(window).trigger('resize');

thanks - i will try it out. since the issue comes up so infrequently, we might not know if this solves the issue for a year or so!

I think this might happen in the case where the script has been run but the page has not finished loading yet. To avoid these kind of issues one has to try to initialise the page properly. This is achievable for example by including your scripts the last thing on your HTML document

this is one global ‘php’ page with a single div at the bottom, that loads other pages and displays them. i had to go this route for technical reasons.

your code is now in place at the very end of the html. good luck to both of us! (i am tempted to put your name as a console.log display and give you the credit, or the blame)

edit: i wrapped the thing with a one second timeout too just to be sure.

1 Like

setTimeouts to fix things like that reminds me of back in the day hot fixes while I’m dying to get out of the office :stuck_out_tongue:

1 Like

i will never understand why “lazy” has a negative connotation associated with it. i see it as a very positive attribute. :wink: :wink:

Lazy is a good thing when it helps you find the most cost effective solution without any drawbacks. However when lazy means hacking upon hacks you will end up with a difficult to understand and unmaintainable application, for which your initial lazy approach will get you closer to ‘hell’ instead. In programming you cannot be lazy without being clever and thinking ahead, and most of the times we make mistakes by trying to be too clever. The proper solution for this may be finding the bit of code that loads each page, and putting your code right after the HTML is inserted and that dynamic div has been initialised

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.