# Perspective Mouse Click & Drag

**URL:** <https://forum.inductiveautomation.com/t/perspective-mouse-click-drag/28583>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [September 26, 2019, 1:55pm UTC](https://forum.inductiveautomation.com/t/perspective-mouse-click-drag/28583 "2019-09-26T13:55:07Z")\
**Posts on this page:** 20\
**Page:** 3

<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:** [November 7, 2022, 8:11am UTC](https://forum.inductiveautomation.com/t/perspective-mouse-click-drag/28583/41 "2022-11-07T08:11:31Z")

</div>

Hi Victor,

It seems the script tag doesn't work in Markdown. Do you have any workaround for that?

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [November 7, 2022, 8:42am UTC](https://forum.inductiveautomation.com/t/perspective-mouse-click-drag/28583/42 "2022-11-07T08:42:35Z")

</div>

> [@nader.chinichian](#):
>
> the tag

what tag?

---

<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:** [November 7, 2022, 9:05am UTC](https://forum.inductiveautomation.com/t/perspective-mouse-click-drag/28583/43 "2022-11-07T09:05:51Z")

</div>

Sorry I meant inline script html tag

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [November 7, 2022, 10:37am UTC](https://forum.inductiveautomation.com/t/perspective-mouse-click-drag/28583/44 "2022-11-07T10:37:33Z")

</div>

ahh yes, it doesnt.  
Well not as you would expect atleast. It will not run on load.

A workaround is to put your script in onload of an image. I did something like that here.

> [@Javascript inject in Perspective... have fun](https://forum.inductiveautomation.com/t/javascript-inject-in-perspective-have-fun/65805/5):
>
> Gonna try to keep this topic updated with all my cool injectings stuck_out_tongue Version 8.1.22 svg clicker wink

Becareful though... running js scripts onload can break the designer. (ex: don't do an alert)

```auto
"<img style='display:none' src='/favicon.ico' onload=\" your script \"></img>"

```

---

<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:** [November 13, 2022, 8:06am UTC](https://forum.inductiveautomation.com/t/perspective-mouse-click-drag/28583/45 "2022-11-13T08:06:30Z")

</div>

Hi Victor,  
Do you think it is possible to get the runtime width and height of an object with the Markdown trick?  
What I really always want is to know the runtime of the view size itself(like embedded view) in runtime.  
For example, if I put an invisible SVG with w: 100% h:100% in a view and use the .getTotalLength() method to get the actual size which triggers the code every time the size is changed I can get the view size.

Or may be something simpler.

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [November 14, 2022, 8:36am UTC](https://forum.inductiveautomation.com/t/perspective-mouse-click-drag/28583/46 "2022-11-14T08:36:17Z")

</div>

Not 100% sure what you are trying to do here. but this should get you the some bounds on resize.  
I forgot to check if it was the views or the markdown one. probably the view, (else you'll need to add an other _parentNode_)  
You could also get the size of your svg component if it has a domID, you can change the queryselector to `#id` instead of `[data-component-path]` (think like css selectors)

```auto
 	value = #your view custom key name
	code = "<img style='display:none' src='/favicon.ico' onload=\"const componentPath = this.parentNode.parentNode.parentNode.parentNode.getAttributeNode('data-component-path'); const view = [...window.__client.page.views._data.values()].find(view => view.value.mountPath == componentPath.value.split('.')[0]).value; window.addEventListener('resize',function(){ const viewNode = document.querySelector('[data-component-path='+CSS.escape(componentPath.value)+']'); view.custom.write('"+value+"',{...viewNode.getBoundingClientRect().toJSON()});}) \"></img>"
	return code

```

---

<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:** [November 14, 2022, 7:18pm UTC](https://forum.inductiveautomation.com/t/perspective-mouse-click-drag/28583/47 "2022-11-14T19:18:28Z")

</div>

Thanks, Victor, this new JS code injection trick of yours opens a lot of possibilities that are only possible by creating a module.

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [November 15, 2022, 7:26am UTC](https://forum.inductiveautomation.com/t/perspective-mouse-click-drag/28583/48 "2022-11-15T07:26:54Z")

</div>

Hehe yes, its usefull to be able to have access to the source language/code of the frontend.  
For bigger/complex things you are still better of with a module though 😛

---

<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:** [November 16, 2022, 4:36am UTC](https://forum.inductiveautomation.com/t/perspective-mouse-click-drag/28583/49 "2022-11-16T04:36:37Z")

</div>

I wonder is it possible to use your trick inside iframe?  
If it is possible we can do anything and finally pass the result to perspective view params

---

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [November 16, 2022, 5:16am UTC](https://forum.inductiveautomation.com/t/perspective-mouse-click-drag/28583/50 "2022-11-16T05:16:06Z")

</div>

I am not 100% sure what the goal is here, but what about these steps:

1. Create a web-dev text resource that is the html page you are trying to build to interact with Perspective
2. Show that text resource in an iframe
3. Reference `parent.window.__client.page` to talk to the parent page for whatever reason
4. Use that reference to interact with the base page?

This sounds like what you are trying to do, but I am not 100% positive

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [November 16, 2022, 7:33am UTC](https://forum.inductiveautomation.com/t/perspective-mouse-click-drag/28583/51 "2022-11-16T07:33:45Z")

</div>

It highly depends on the website inside the iframe.  
Generally you wont have access to what is clicked inside it. Though some sites desinged to be used as iframes do have extra things that they expose.  
Which you then could probably access with the javascript

---

<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:** [November 16, 2022, 10:58am UTC](https://forum.inductiveautomation.com/t/perspective-mouse-click-drag/28583/52 "2022-11-16T10:58:51Z")

</div>

Yes, exactly and what is the syntax to target view.custom.xxx properties?  
I mean with parent.window.\_\_client.page how can I read and write perspective view properties?

---

<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:** [November 16, 2022, 11:02am UTC](https://forum.inductiveautomation.com/t/perspective-mouse-click-drag/28583/53 "2022-11-16T11:02:51Z")

</div>

The point I want to write the iframe code myself to interact with perspective view.  
Just read and write view.custom.xxx property inside JavaScript code inside iframe is enough for me.

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

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [November 16, 2022, 1:41pm UTC](https://forum.inductiveautomation.com/t/perspective-mouse-click-drag/28583/54 "2022-11-16T13:41:03Z")

</div>

If you can controll the Iframe, then i think your best bet will be to send a message to the parent from there.  
And then in perspective use the jsinjection to read the messages.

iframe:

```auto
// Called from the iframe
const message = JSON.stringify({
    message: 'Hello from iframe',
    date: Date.now(),
});
window.parent.postMessage(message, '*');

```

perspective: (not tested)

```auto
window.addEventListener('message', function (e) {const data = JSON.parse(e.data); view.custom.write('key',data);})

```

something like this i guess:

```auto
 	value = #your view custom key name
	code = "<img style='display:none' src='/favicon.ico' onload=\"const componentPath = this.parentNode.parentNode.parentNode.parentNode.getAttributeNode('data-component-path'); const view = [...window.__client.page.views._data.values()].find(view => view.value.mountPath == componentPath.value.split('.')[0]).value; window.addEventListener('message', function (e) {const data = JSON.parse(e.data); view.custom.write('"+value+"',data);}); \"></img>"
	return code

```

You can send message to the iframe with  
(in the onload):  
`document.querySelector('#youriframeid').postMessage("+yourjsonstring+",'*')`

And read it in the iframe also with the eventlistener  
`window.addEventListener('message', function (e) {const data = JSON.parse(e.data); ...})`

* * *

you might be able to access the client directly, with window.frameElement and window.parent... but not sure if that will be possible. try this in your iframe i guess

```auto
const componentPath = window.frameElement.parentNode.getAttributeNode('data-component-path');
 const view = [...window.parent.__client.page.views._data.values()].find(view => view.value.mountPath == componentPath.value.split('.')[0]).value; 
view.custom.write('yourperspectivekey',data);});

```

---

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [November 16, 2022, 3:35pm UTC](https://forum.inductiveautomation.com/t/perspective-mouse-click-drag/28583/55 "2022-11-16T15:35:01Z")

</div>

I Wonder if it’s possible to trigger the native perspective message handlers this way, not sure if those are triggered in the front end of the backend

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [November 16, 2022, 3:47pm UTC](https://forum.inductiveautomation.com/t/perspective-mouse-click-drag/28583/56 "2022-11-16T15:47:56Z")

</div>

Pretty sure those are in the gateway backend, not in javscript frontend.

Hm though maybe you could access those in an other way through the client context.  
definently not with a window.postMessage

---

<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:** [November 17, 2022, 7:40pm UTC](https://forum.inductiveautomation.com/t/perspective-mouse-click-drag/28583/57 "2022-11-17T19:40:17Z")

</div>

So it is not possible yet

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [November 18, 2022, 7:39am UTC](https://forum.inductiveautomation.com/t/perspective-mouse-click-drag/28583/58 "2022-11-18T07:39:58Z")

</div>

> [@kgamble](#):
>
> trigger the native perspective message handlers

This i have not found yet no.

Your iframe messages should work, i think

---

<div class="post-metadata">

**Author:** ![chaoliang](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@chaoliang](https://forum.inductiveautomation.com/u/chaoliang)\
**Post date:** [December 16, 2022, 6:08am UTC](https://forum.inductiveautomation.com/t/perspective-mouse-click-drag/28583/59 "2022-12-16T06:08:37Z")

</div>

nice work.

---

<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:** [May 12, 2023, 2:27pm UTC](https://forum.inductiveautomation.com/t/perspective-mouse-click-drag/28583/60 "2023-05-12T14:27:16Z")

</div>

Can you make it to also select alpha channel?  
This colour picker only accept RGB and no option for opacity or alpha channel

[Previous page](https://forum.inductiveautomation.com/t/perspective-mouse-click-drag/28583.md?page=2)

[Next page](https://forum.inductiveautomation.com/t/perspective-mouse-click-drag/28583.md?page=4)
