I have a scenario where a user when clicks on a link, they are directed to a page in which I want to add a code to fetch a variable and redirect to another page.
i.e. user clicks on <a href="sample.tpl">click here</a>
on sample.tpl I want to write a code to redirect him to another page
<script>
window.location="http://example.com/?page_id=10"
but I want to send a variable too on this new link without appending it to the URL for security reasons.
How can I do it with some safe procedure?
Do ask me questions if it is not clear.
You could create a form with
method="post", ahiddeninput with the value you want to pass and asubmitbutton styled as a regular link (if you want to also manually send the form).Then just submit the form manually or programmatically through the
submit()methodExample (with automatic redirect after 3 seconds after page load)
http://jsbin.com/avacoj/1/edit
Html
Js
As a side note you may consider to insert a
submitbutton inside<noscript></noscript>tag so the redirect will be possibile even when js is not available on the user device, so the page is still accessible.