# 8.1.4 Perspective openPopup new arg viewportBound doesn't and doesn't resize apply if position supplied opens it off screen

**URL:** <https://forum.inductiveautomation.com/t/8-1-4-perspective-openpopup-new-arg-viewportbound-doesnt-and-doesnt-resize-apply-if-position-supplied-opens-it-off-screen/43991>\
**Category:** Ignition Early Access\
**Tags:** ignition80, perspective\
**Created:** [March 2, 2021, 2:35pm UTC](https://forum.inductiveautomation.com/t/8-1-4-perspective-openpopup-new-arg-viewportbound-doesnt-and-doesnt-resize-apply-if-position-supplied-opens-it-off-screen/43991 "2021-03-02T14:35:51Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [March 2, 2021, 2:35pm UTC](https://forum.inductiveautomation.com/t/8-1-4-perspective-openpopup-new-arg-viewportbound-doesnt-and-doesnt-resize-apply-if-position-supplied-opens-it-off-screen/43991/1 "2021-03-02T14:35:51Z")

</div>

b2021022614

If you use the `system.perspective.openPopup` function to open a popup at the mouse cursor and resize popup via the `position` arg with the new `viewportBound` option set to `True`, then the popup may open _off the screen_ and if so, it _won’t resize_. If the off-screen popup is then moved, its position is then correctly bound to the viewport, but the popup is not sized according to the width/height specified in the `position` argument.

If the popup is opened within the bounds, then all is good.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [March 2, 2021, 3:46pm UTC](https://forum.inductiveautomation.com/t/8-1-4-perspective-openpopup-new-arg-viewportbound-doesnt-and-doesnt-resize-apply-if-position-supplied-opens-it-off-screen/43991/2 "2021-03-02T15:46:02Z")

</div>

Could you post a screenshot of the Popup configuration you have in place? I’m trying to replicate this and have so far been unable to. Part of it could be the wording in your post; it reads as if you’re using a script and the Popup action at the same time, because you call out a script, but then you specify that the checkbox is checked.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [March 2, 2021, 3:50pm UTC](https://forum.inductiveautomation.com/t/8-1-4-perspective-openpopup-new-arg-viewportbound-doesnt-and-doesnt-resize-apply-if-position-supplied-opens-it-off-screen/43991/3 "2021-03-02T15:50:18Z")

</div>

I updated the wording in my post, I’m using purely scripting to open the popup.

This is my script, might be hard to test it without the stuff it relies on… but you could just pull out the call to the openPopup function:

```auto
def openDevicePopup(self, event):
	"""
	Description:
	Opens up the standard device popup and sizes it according to the typeId of the device using the lookup table tag.
	"""
	controlEnable = self.view.params.controlEnable
	deviceParentPath = self.view.params.deviceParentPath
	deviceName = self.view.params.deviceName
	popupID = 'device-popup-%s-%s' % (deviceParentPath, deviceName)
	
	popupHeightDefault = 550
	popupHeight = popupHeightDefault
	try:
		TypeId = system.tag.readBlocking([deviceParentPath + '/' + deviceName + '.typeId'])[0].value
# system.perspective.print('TypeID: {}'.format(TypeId))
		UDTLookupData = system.dataset.toPyDataSet(system.tag.readBlocking(['[default]System/Datasets/UDTPopupPaths_Perspective'])[0].value)
# system.perspective.print('UDTLookupData: {}'.format(UDTLookupData))
		for i, row in enumerate(UDTLookupData):
			if row['UDTParentType'] == TypeId:
				popupHeight = row['PopupHeight']
				break
		# TODO: error checking...
	except:
		pass
	
	system.perspective.print('popupHeight: {}'.format(popupHeight if popupHeight != 0 else '<default>'))
	if popupHeight == 0:
		popupHeight = popupDefaultHeight
	
	system.perspective.openPopup(id=popupID,
								 view='_Templates/Devices/Control/Device Popup Individual'
								 ,params={'controlEnable':controlEnable
										 ,'deviceParentPath':deviceParentPath
										 ,'deviceName':deviceName
										 ,'popupId': popupID
										 ,'popupHeight': popupHeight}
								 ,position={'left':event.clientX
										   ,'top':event.clientY-200
										   ,'height':popupHeight}
								 ,showCloseIcon=True
								 ,draggable=True
								 ,viewportBound=True
								 )

```

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [March 2, 2021, 3:58pm UTC](https://forum.inductiveautomation.com/t/8-1-4-perspective-openpopup-new-arg-viewportbound-doesnt-and-doesnt-resize-apply-if-position-supplied-opens-it-off-screen/43991/4 "2021-03-02T15:58:20Z")

</div>

So, wait... You're intentionally opening it out of bounds, but you're also trying to restrict it to be bound to the viewport?

> [@nminchin](#):
>
> position={'left':event.clientX ,'top':event.clientY-200 ,'height':popupHeight}  
> ...  
> viewportBound=True

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [March 2, 2021, 3:59pm UTC](https://forum.inductiveautomation.com/t/8-1-4-perspective-openpopup-new-arg-viewportbound-doesnt-and-doesnt-resize-apply-if-position-supplied-opens-it-off-screen/43991/5 "2021-03-02T15:59:58Z")

</div>

Well, I can’t check the bounds myself and I want to do more stuff than I can do using the Popup action, so I have to do my own “open at mouse cursor” code. But due to not being able to check how large the viewport is, I was relying on the viewportBound to constrain it. To me, if the condition is checked, then it shouldn’t let a popup open outside of the bounds

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [March 2, 2021, 4:04pm UTC](https://forum.inductiveautomation.com/t/8-1-4-perspective-openpopup-new-arg-viewportbound-doesnt-and-doesnt-resize-apply-if-position-supplied-opens-it-off-screen/43991/6 "2021-03-02T16:04:12Z")

</div>

The viewportBound property will do it's best to resize or re-position a popup such that the popup is not opened off of the viewport, but if you expressly define a position which is off the viewport, then we have to abide by your very specific demands as to where the popup should open. Once the popup is moved, we then take the opportunity to "snap" the popup to be within the viewport.

> [@nminchin](#):
>
> To me, if the condition is checked, then it shouldn’t let a popup open outside of the bounds

The problem here is you are defining two very contradictory behaviors. Your script is expressly telling the application to open a popup outside the viewport, and then you're telling the application to not allow the popup to open outside the viewport.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [March 2, 2021, 4:07pm UTC](https://forum.inductiveautomation.com/t/8-1-4-perspective-openpopup-new-arg-viewportbound-doesnt-and-doesnt-resize-apply-if-position-supplied-opens-it-off-screen/43991/7 "2021-03-02T16:07:15Z")

</div>

That’s fair enough, but I can’t do this any other way as I don’t have any visibility of how large the viewport is 😕 So I’m stuck either opening every device popup in the middle of the screen, or opening the popup for devices on the bottom half of the page half off the screen, neither of which are ideal.

Do you know when the viewport dimensions will be available in Perspective?

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [March 2, 2021, 4:09pm UTC](https://forum.inductiveautomation.com/t/8-1-4-perspective-openpopup-new-arg-viewportbound-doesnt-and-doesnt-resize-apply-if-position-supplied-opens-it-off-screen/43991/8 "2021-03-02T16:09:01Z")

</div>

In your script, what do `clientX` and `clientY` refer to? I guess what I would like to know is why you need to open the Popup “up” 200px…

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [March 2, 2021, 4:10pm UTC](https://forum.inductiveautomation.com/t/8-1-4-perspective-openpopup-new-arg-viewportbound-doesnt-and-doesnt-resize-apply-if-position-supplied-opens-it-off-screen/43991/9 "2021-03-02T16:10:34Z")

</div>

They come from the event passed into it from a button onActionPerformed action.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [March 2, 2021, 4:10pm UTC](https://forum.inductiveautomation.com/t/8-1-4-perspective-openpopup-new-arg-viewportbound-doesnt-and-doesnt-resize-apply-if-position-supplied-opens-it-off-screen/43991/10 "2021-03-02T16:10:59Z")

</div>

So couldn’t you perform your own check to see if `clientY-200` is less than `0`? Also, I suspect this is actually an onClick action.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [March 2, 2021, 4:13pm UTC](https://forum.inductiveautomation.com/t/8-1-4-perspective-openpopup-new-arg-viewportbound-doesnt-and-doesnt-resize-apply-if-position-supplied-opens-it-off-screen/43991/11 "2021-03-02T16:13:04Z")

</div>

These are clientY/X below. They're just the mouse coords, I don't have any context of where that is in relation to the bounds of the viewport

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/c/5cb16e13214f84e1d0c79e3dbfe1a8033919c54a.png)

> [@cmallonee](#):
>
> I guess what I would like to know is why you need to open the Popup “up” 200px…

That's a good question.. The script wasn't working and I just jumped back onto it, so from memory it was just part of testing. It shouldn't be in there. It's gone now 🙂 I think it was there for any devices on the very bottom of the screen so that the operator could actually see at least some of the popup.. I think I still need it in there for now

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [March 2, 2021, 4:17pm UTC](https://forum.inductiveautomation.com/t/8-1-4-perspective-openpopup-new-arg-viewportbound-doesnt-and-doesnt-resize-apply-if-position-supplied-opens-it-off-screen/43991/12 "2021-03-02T16:17:14Z")

</div>

I just checked in a browser, and the `clientY` is the distance from the top of the viewport to the pixel in which the click event occurred. So you don’t need to know anything about the viewport, you just need to know if the `clientY` value is more than 200. If it is not, then you need to adjust that “top” position to be `clientY`.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [March 2, 2021, 4:18pm UTC](https://forum.inductiveautomation.com/t/8-1-4-perspective-openpopup-new-arg-viewportbound-doesnt-and-doesnt-resize-apply-if-position-supplied-opens-it-off-screen/43991/13 "2021-03-02T16:18:58Z")

</div>

That works for buttons calling popups at the top of the page, but not for those at the bottom. There’s no way to know how ‘deep’ the page is with just a from-top and left mouse coord. The 200px “up” was just to lift up those opened when the mouse was positioned at the bottom of the screen, otherwise you end up with this (black bottom part is “off the screen”) i.e. you just see the titlebar and nothing else:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/6/f64f99bf7b858f8e8ec259adf0955557c4f3ed54.png)

What I need to do is not fix the 200px, and make it dynamic based on the viewport dimensions and the height of the popup, and the mouse coord

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [March 2, 2021, 4:23pm UTC](https://forum.inductiveautomation.com/t/8-1-4-perspective-openpopup-new-arg-viewportbound-doesnt-and-doesnt-resize-apply-if-position-supplied-opens-it-off-screen/43991/14 "2021-03-02T16:23:51Z")

</div>

Ah, yes. The only way to handle cases like that via scripting at this time is to make an educated guess in the logic you’re using to open the popup.

Something like

```auto
if event.clientY >= popupDefaultHeight:
    # build positional array here, using "bottom" instead of top.
else:
    # build positional array as you've been doing, but minus the 200 modifier.

```

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [March 2, 2021, 4:26pm UTC](https://forum.inductiveautomation.com/t/8-1-4-perspective-openpopup-new-arg-viewportbound-doesnt-and-doesnt-resize-apply-if-position-supplied-opens-it-off-screen/43991/15 "2021-03-02T16:26:32Z")

</div>

> [@cmallonee](#):
>
> using "bottom" instead of top

Oh... I totally missed that I could use that 🙃 that's what I get for working till 3am 😕  
Thanks!

Actually, this works too:

```auto
	position = {'left':event.clientX
			   ,'height':popupHeight}
	if event.clientY >= popupHeight:
		# a bit dodgy but it's the best we can do without knowing the viewport dimensions...
		position['top'] = event.clientY - popupHeight
	else:
		position['top'] = event.clientY	

```

I think there's still a bug with the resizing though if it's opened off the screen - it makes it far taller when you drag it. I set the height to 450, but if opened off the page and dragged into view, it's about 750.

---

<div class="post-metadata">

**Author:** ![bruno.nunes](https://avatars.discourse-cdn.com/v4/letter/b/a5b964/32.png) [@bruno.nunes](https://forum.inductiveautomation.com/u/bruno.nunes)\
**Post date:** [May 25, 2022, 3:15pm UTC](https://forum.inductiveautomation.com/t/8-1-4-perspective-openpopup-new-arg-viewportbound-doesnt-and-doesnt-resize-apply-if-position-supplied-opens-it-off-screen/43991/16 "2022-05-25T15:15:12Z")

</div>

Is this the same problem, or am I just doing something wrong?

Example with viewportbound:  
 ![with_viewportbound](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/c/6ccb2ddd8ab4a9c17629af4648dae3917ead190c.gif)

Example without viewportbound:  
 ![without_viewportBound](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/b/fbfcfab432667a05f8324def3ef6f41063968a85.gif)

Thank you.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [May 25, 2022, 4:34pm UTC](https://forum.inductiveautomation.com/t/8-1-4-perspective-openpopup-new-arg-viewportbound-doesnt-and-doesnt-resize-apply-if-position-supplied-opens-it-off-screen/43991/17 "2022-05-25T16:34:36Z")

</div>

There are three things going on in the example which includes use of viewportBound:

1. Even when `viewportBound` is `True`, we must above all else honor the specified position of the Popup. As a result, your Popup absolutely will be opened at the `event.clientX` and `event.clientY` position. This means that your Popup will be opened with some of the content partially outside of the viewport. ( **Working as expected** )
2. When a Popup is viewport-bound, and has any portion of itself outside the viewport bounds, and the Popup is dragged/resized, the Popup will immediately reposition itself inside the viewport boundaries. ( **Working as expected** )
3. When the popup repositions itself, it must redraw itself by calculating the new origin (top-left corner) and overall dimensions of the Popup based on the current position and the dimensions of the Popup. ( **NOT working as expected** )

I’ll open an internal ticket to track this issue and get it resolved.

**Workaround:**  
In the meantime, this can be worked around by not specifying a position for the Popup, OR by using the Popup Action instead and using a _relative_ positioning approach.

---

<div class="post-metadata">

**Author:** ![nader.chinichian](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nader.chinichian/32/9261_2.png) [@nader.chinichian](https://forum.inductiveautomation.com/u/nader.chinichian)\
**Post date:** [January 4, 2025, 7:03am UTC](https://forum.inductiveautomation.com/t/8-1-4-perspective-openpopup-new-arg-viewportbound-doesnt-and-doesnt-resize-apply-if-position-supplied-opens-it-off-screen/43991/18 "2025-01-04T07:03:29Z")

</div>

> [@cmallonee](#):
>
> approach

Any update for fixing this bug? (After two years)  
I really need to open the popup related to the position of the user's mouse click, and if the popup area is out of the viewport, it should rearrange itself.  
Now, it can be achieved via Popup Action Wizard but not in script.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [January 6, 2025, 4:40pm UTC](https://forum.inductiveautomation.com/t/8-1-4-perspective-openpopup-new-arg-viewportbound-doesnt-and-doesnt-resize-apply-if-position-supplied-opens-it-off-screen/43991/19 "2025-01-06T16:40:36Z")

</div>

No, the ticket is still far down in the backlog. It doesn't look like the issue has been encountered at a large scale so it's been marked as a low priority. With everything else being worked on for 8.3 I would not expect this to be fixed anytime soon.

---

<div class="post-metadata">

**Author:** ![Ryan\_Marsh](https://avatars.discourse-cdn.com/v4/letter/r/ad7895/32.png) [@Ryan\_Marsh](https://forum.inductiveautomation.com/u/Ryan_Marsh)\
**Post date:** [April 8, 2026, 1:29pm UTC](https://forum.inductiveautomation.com/t/8-1-4-perspective-openpopup-new-arg-viewportbound-doesnt-and-doesnt-resize-apply-if-position-supplied-opens-it-off-screen/43991/20 "2026-04-08T13:29:25Z")

</div>

Posting here so people know it’s not fixed yet.

I have a pop up that needs to appear in the bottom corner-ish of a view, and if the view isn’t in kiosk mode, or it’s on a screen with a different resolution, it will overflow below the view, causing it to expand to cover top to bottom when someone tries to move it.
