Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simulate browser resize on page first load

I have a dashboard web application. It contains some controls on it which are sized based on the browser and are also resizeable by the user. They are dynamically created and, as such, I persist their dimensions through page postbacks by storing their state in Session and in a database.

When my dashboard first loads there is a chance that I am pulling data out of the Database onto a monitor which is not the same size as when the data was written to the Database. The controls need to be resized proportional to how they were before. Fortunately, it appears that the controls are able to resize themselves to the correct, proportional dimensions if they believe they need to re-calculate their dimensions.

As such, on first page load, I would like to simulate the browser resizing. Is it possible to do something like this in javascript?

like image 394
Sean Anderson Avatar asked Aug 08 '11 22:08

Sean Anderson


People also ask

How do I render a component when browser is resized?

You can listen to the resize event in componentDidMount() and then update the dimensions ( width and height ). You should remove the listener in componentWillUnmount() method.

How do you fire a window resize event?

In this case, we will use the native JavaScript event 'resize' in order to trigger the resize event as per our convenience. The syntax would be: $(window). trigger('resize'); $(<element>).


1 Answers

The controls probably resize on window.onresize event. If you want to trigger this event you can do window.onresize(); after the page loads.

To wait for the apge to load you can add it to the window.onload event.

like image 50
amosrivera Avatar answered Sep 18 '22 23:09

amosrivera