admin管理员组文章数量:1130349
I have a landing page with 3 buttons that have respective functions with them to hide/unhide content based on user selection of those three buttons.
Is there a way I can have the user land directly on a particular function?
so the base URL is domain/page
domain/page/function1 would land on the page with function1 enabled.
I have a landing page with 3 buttons that have respective functions with them to hide/unhide content based on user selection of those three buttons.
Is there a way I can have the user land directly on a particular function?
so the base URL is domain/page
domain/page/function1 would land on the page with function1 enabled.
Share Improve this question asked Oct 18, 2018 at 8:03 Tahir LatifTahir Latif 1 2- What type of function? JavaScript/jQuery? PHP? – Jacob Peattie Commented Oct 18, 2018 at 10:41
- Oh sorry about the delay. I didn't see the notification. It's javascript native – Tahir Latif Commented Oct 28, 2018 at 9:20
1 Answer
Reset to default 0You have a few options.
GET Parameter
The easiest one is to add a GET parameter to the url of the links, so you call it like this: domain/page?function=1
Then, on your page page, you can access this parameter using global array $_GET['function'] and do your logic as you wish.
POST Parameter - wrap into forms
If you don't want it to be seen, you can wrap your links in separate form elements, with action set to domain/page, the link would be an input type='submit', and also add an input field type='hidden' with name='function' value='1'. Then you can access this value on your page page with global $_POST['function'] array. More about forms here.
Register custom routes
You can do exactly like you wanted, accessing domain/page/1 can make the get_query_var('function') set to 1 on page page, but you need to register a custom url route in WordPress.
This has been answered already, so I'll just point you to it here.
Warning
Whatever option you choose, please don't forget to wrap the value of your parameter inside htmlspecialchars() function. More about that here.
I have a landing page with 3 buttons that have respective functions with them to hide/unhide content based on user selection of those three buttons.
Is there a way I can have the user land directly on a particular function?
so the base URL is domain/page
domain/page/function1 would land on the page with function1 enabled.
I have a landing page with 3 buttons that have respective functions with them to hide/unhide content based on user selection of those three buttons.
Is there a way I can have the user land directly on a particular function?
so the base URL is domain/page
domain/page/function1 would land on the page with function1 enabled.
Share Improve this question asked Oct 18, 2018 at 8:03 Tahir LatifTahir Latif 1 2- What type of function? JavaScript/jQuery? PHP? – Jacob Peattie Commented Oct 18, 2018 at 10:41
- Oh sorry about the delay. I didn't see the notification. It's javascript native – Tahir Latif Commented Oct 28, 2018 at 9:20
1 Answer
Reset to default 0You have a few options.
GET Parameter
The easiest one is to add a GET parameter to the url of the links, so you call it like this: domain/page?function=1
Then, on your page page, you can access this parameter using global array $_GET['function'] and do your logic as you wish.
POST Parameter - wrap into forms
If you don't want it to be seen, you can wrap your links in separate form elements, with action set to domain/page, the link would be an input type='submit', and also add an input field type='hidden' with name='function' value='1'. Then you can access this value on your page page with global $_POST['function'] array. More about forms here.
Register custom routes
You can do exactly like you wanted, accessing domain/page/1 can make the get_query_var('function') set to 1 on page page, but you need to register a custom url route in WordPress.
This has been answered already, so I'll just point you to it here.
Warning
Whatever option you choose, please don't forget to wrap the value of your parameter inside htmlspecialchars() function. More about that here.
本文标签: javascriptLanding function through URL
版权声明:本文标题:javascript - Landing function through URL 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749251678a2339795.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论