# Cloud CDF and HTTPRedirect

Cross posted on community.wolfram.com

### Question and requirements

Is it possible to HTTPRedirect from a Cloud CDF via e.g. Button action?

• I need an interactive cloud cdf around it.

• The action would not only redirect but evaluate arbitrary code prior to that.

• If it matters the target page does not need to be any page but an arbitrary CloudObject is enough.

• No, I don't want to hide old stuff and show new to the user, I really need to redirect.

• No, open in new tab does not count.

So it would work analogously to this form's submit button:

CloudDeploy[
FormFunction[{"go on and submit"}
, link = CloudPut[RandomReal[], Permissions -> "Public"]
] &
]
, Permissions -> "Public"
]


### Problems

Wasn't able to achieve that, here's why:

• Form/ApiFunctions where HTTPRedirect works well can't have interative CDFs embedded inside:

 CloudDeploy[
FormFunction[
{ "this is ok"
, ExportForm["this is not ok", "CloudCDFElement"]
}
, foo
]
, Permissions -> "Public"
]


• and I can't trigger HTTPRedirect from cloud CDF, nothing happens:

    CloudDeploy[
ExportForm[
Button["Submit", Print[1]; HTTPRedirect["http://www.wolfram.com"]],
"CloudCDFElement"
], Permissions -> "Public"
]


• Do you need both an actual and a hyperlink? You can obviously restyle a Hyperlink to look like a button. A SystemOpen call works too, except it's viewed as a popup. Is that okay? – b3m2a1 Aug 4 '17 at 15:59
• @b3m2a1 nope, see above requirements :) – Kuba Aug 4 '17 at 16:15
• Ah. That's tougher. Well I'll keep playing with it. – b3m2a1 Aug 4 '17 at 16:16
• So I took a break and came back to it and I'm not entirely sure WRI's made this possible yet. If you open a cloud notebook and make a hyperlink there, you can disable "Open in New Tab", but it doesn't actually do that. Since we don't have access to JS it's a lot harder. EmbeddedHTML seems to only let you work with iframes and I can't access the StyleDefinitions in the cloud so clearly they're baked in. – b3m2a1 Aug 4 '17 at 19:48
• @b3m2a1 thanks for your time, yes I was afraid it may be impossible :-/ Cloud front end setup is way more obscure than desktop's so one never knows what is implemented/isn't/won't be etc. – Kuba Aug 4 '17 at 20:01

Here are results of my experiments, so far works:

CloudDeploy[
ExportForm[
DynamicModule[{x = 1}, Column[{
Slider@Dynamic@x,
Dynamic@x,
Button["Test redirect",
Print @ EmbeddedHTML[ StringTemplate[
"<script>window.top.location.href =\"\"</script>"

.top. was added because EmbeddedHTML translates to an iframe and we don't want to redirect only that iframe itself. On the other hand your cloud object may be embedded in another page and .top. will redirect the whole page. You may need that or not, depends, at the end I'm using .parent. because I want to redirect only the CloudObject parent iFrame.
• I found this Q/A very helpful - much thanks! BTW... CloudDeploy[ ExportForm[ Manipulate[ Column[{ a, Button["Test redirect", Module[ {link}, link = "mathematica.stackexchange.com"; Print@EmbeddedHTML[ StringTemplate[ "<script>window.top.location.href =\"\"</script>"]@link]] ] }], {a, 0, 2}], "CloudCDF"], "testButtonV2", Permissions -> "Public"] My preference is Manipulate over DynamicModule but it's situational. – Mitch Feb 28 '18 at 19:20