Go to URL -> Execute javascript -> prceed to layout 2

Get help using Construct 2

Post » Sat Oct 15, 2016 9:20 pm

Would it be possible to make something like:

Button - on press -> go to url - www.example.com - target self
-> execute javascript (alert("hello"))
-> go to Layout 2

For now, all I can get is a browser opening destination url, but not executing javasctipt (alert for example) nor proceeding to Layout 2...
Image
B
7
S
1
Posts: 70
Reputation: 843

Post » Sat Oct 15, 2016 9:49 pm

Target self means it's going to go to a new url, and leave the current one
You can't change your shirt, if it's at your house, and you are at the neighbours.
Image ImageImage
B
168
S
50
G
164
Posts: 8,235
Reputation: 105,589

Post » Sat Oct 15, 2016 10:45 pm

Hi, thanks, but target blank opens a new tab and runs the javascript alert on the initial tab and not on the new one... Is there a way to "take the shirt with you" to the neighbours hose, change it there and then get back home? :)
Image
B
7
S
1
Posts: 70
Reputation: 843

Post » Sat Oct 15, 2016 11:24 pm

You will have to ask the neighbours.
Image ImageImage
B
168
S
50
G
164
Posts: 8,235
Reputation: 105,589

Post » Mon Oct 17, 2016 6:08 pm

You can't run javascript in other tabs. That would be a huge security flaw in the web. For example a malicious page could open your Facebook page and send all your photos to the malicious page owner. So actually it's a pretty good thing you can't do that.
Scirra Founder
B
387
S
230
G
88
Posts: 24,251
Reputation: 192,454

Post » Tue Oct 18, 2016 1:18 pm

Ashley wrote:You can't run javascript in other tabs.

I understand the security risk, but could I run JS in same tab? For example, if I'd like to make a game that opens website in the background with some sort of overlay UI built in C2? I'd like to use some sort of buttons that would fire JS on the page in the background (find some elements, change inner html, change style of divs etc...) (Idea is sort of an educational game/ap)
Image
B
7
S
1
Posts: 70
Reputation: 843

Post » Tue Oct 18, 2016 2:59 pm

I think you might be able to overlay an iframe, but you still can't force it to run your own JS, for the same reasons.
Scirra Founder
B
387
S
230
G
88
Posts: 24,251
Reputation: 192,454

Post » Tue Oct 18, 2016 6:43 pm

Couldn't you achieve the same effect using local storage?

Not sure best way but maybe:
On layout start -> set global variable to random number

On button -> store global variable into local storage, open new window

If global variable =! local storage then fire javascript

I actually haven't used local storage yet so doubt that is exactly how it would go but hopefully that conveyed the premise. I've used mySQL tables before and feel like I could achieve this with them, but figured local storage could as well and would be much simpler
ImageImageImage
B
39
S
22
G
11
Posts: 486
Reputation: 9,913


Return to How do I....?

Who is online

Users browsing this forum: alextro, ivanski1983 and 9 guests