- HMI Model: cMT2108X
- EasyBuilder Pro Version: 6.10.01.259
My js objects use one dialog to interact with them. The dialog should be positioned near the object and for this I write coordinates for the dialog from the object script. There may be cases when the position of the dialog needs to be shifted, as it may go beyond the screen boundary. Therefore, I manually set the screen parameters to position the dialog in the future. This is not convenient because I use models with different resolutions. Can you please tell me if I can get the screen parameters using a javascript function or some other way?
Hello,
One way to get the screen size from a JS Object is to size the JS Object to match the screen (or the bounds you need), then read its width and height attributes from the Canvas widget . To do this, place the following code in the Source tab of the JS Object:
Note: You can find the JS Object in the Object palette under the JS-related dropdown list.
More information for our JS object can be found within our JS SDK:Home - JS Action/Object SDK
Thank you!
Thank you. I wanted something more versatile, without the extra manual work. But I guess I can’t do without it.
I have placed another JS object sized to the screen resolution in CommonWindows, where I get the size of this object and write it to the memory of the JS context.
/*
let ScreenWidth = this.widget.width;
let ScreenHeight = this.widget.height;
window.memoryStorage.setItem(“ScreenWidth”, ScreenWidth);
window.memoryStorage.setItem(“ScreenHeight”, ScreenHeight);
*/
So, when clicking on a JS object, I read the widget parameters in CommonWindows, check if the dialog fits and if not, I move the position.
/*
let ScreenWidth = window.memoryStorage.getItem(‘ScreenWidth’)*1;
let ScreenHeight = window.memoryStorage.getItem(‘ScreenHeight’)*1;
*/
Maybe it will be useful for someone. I would be grateful if someone can suggest a better solution)
P.S. Can’t insert screenshots because of an error that occurs.
Hi @userLDV,
We have fixed the issue on your account related to screenshots, you should be able to include images within posts going forward.