Hi there,
You can't do it like this. When you request a page, it runs at the server first. The generated HTML is then sent to the browser when you can run some JavaScript. This means that for a single request, OnInit always fires before any client side JavaScript.
You could use a two-step approach:
1. Render a normal page just once, let JavaScript collect the screen resolution and submit to the server.
2. Store the resolution in cookies or session variables or elsewhere and use that information for subsequent pages.
This way, you overcome your problem as you collect the info just once in a separate request once at the start of a user's visit.
Cheers,
Imar
|