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
CloudObjectis 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"}
, Module[{link}
, link = CloudPut[RandomReal[], Permissions -> "Public"]
; HTTPRedirect[link]
] &
]
, Permissions -> "Public"
]
Problems
Wasn't able to achieve that, here's why:
Form/ApiFunctionswhereHTTPRedirectworks 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
HTTPRedirectfrom cloud CDF, nothing happens:CloudDeploy[
ExportForm[
Button["Submit", Print[1]; HTTPRedirect["http://www.wolfram.com"]],
"CloudCDFElement"
], Permissions -> "Public"
]
Answer
Here are results of my experiments, so far works:
CloudDeploy[
ExportForm[
DynamicModule[{x = 1}, Column[{
Slider@Dynamic@x,
Dynamic@x,
Button["Test redirect",
Module[{link},
link = "https://mathematica.stackexchange.com";
Print @ EmbeddedHTML[ StringTemplate[
""
]@link
]
]
]}]]
, "CloudCDF"]
, Permissions -> "Public"
]
.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.


Comments
Post a Comment