1

I am new with jQuery and i have to implement multiple redirects on one click event with jquery.
For example on click of button my site should redirect to example.com then example.com1 and then example.com2.
I am not sure this is possible or not with jQuery but my client wants this. I can implement simple redirect with jQuery but i do not know how to implement multiple redirects.
I can share an example for multiple redirects if you ll need for better understanding.
Here is a URL for one of the example. When you will put this URL in browser tab it will have multiple redirects (3). So i hope it will help you to understand. I will really appreciate it if someone would guide me about this. Thank you so much for your time.
http://testing.harbordev.co/website/weather

wplearner
  • 405
  • 6
  • 19
  • jQuery, just like javascript, runs in the browser. When that browser(tab) is navigated away from, the resources are freed. I'm not sure how you expect javascript to continue to redirect from the initial page given this. – Taplar Jun 01 '17 at 19:27
  • Thanks for your response. As i have mentioned above i am not sure it is possible or not. I have only control over first page i have button on this page when that button will clicked, my site should redirect to multiple sites in a loop. This is what my client wants. If you could guide me about this i will really appreciate it. – wplearner Jun 01 '17 at 19:44

1 Answers1

0

To make it (3 consecutive redirects) work you should make a redirect on each of the three pages.

You don't need jQuery for this - one of possible vanilla javascript solutions:

window.location.href = 'newPage.html';

Please check here for more possible answers.

Update: If you don't have control over the pages where the redirection goes the only option that comes to my mind is to open those pages within an iframe of a page that you have control - please check this answer for more detailed help.

Picard
  • 3,745
  • 3
  • 41
  • 50
  • Thanks for your answer but my scenario is little different. I do not have any control over other pages. I have only control on first page where i have button and on click of this button my site will have 3 redirects continuously and i do not have any control over other pages. Can we control browser tab to keep redirecting to other sites. – wplearner Jun 01 '17 at 19:41
  • I really appreciate your answer but my scenario is little different. For clear explanation i am sharing a URL that will demonstrate this scenario. https://www.safehorizon.org/ Please click quick exit site button and then close now button. Then this page will redirect you to multiple sites in a loop. There is some sort of loop because browser back button will start this loop again and again. – wplearner Jun 01 '17 at 19:52
  • When I click that the page opens one new tab plus it redirects itself to http://testing.harbordev.co/website/weather where it makes three redirects within the same domain so we can assume that the author has the control over every of those addresses on the testing.harbordev.co (sub)domain. – Picard Jun 01 '17 at 20:03
  • Ok thank you for your time and help. One last thing i would like to ask. Is it possible to have same kind of functionality for external sites over which we do not have any control? – wplearner Jun 01 '17 at 20:08
  • If it would be possible, anyone could redirect your page to one of his own and steal your clients, traffic etc. the only solution I can think of is the use of a iframe within your page, putting there the external page and changing the iframe'a `src=` attribute according to your needs. – Picard Jun 01 '17 at 20:28
  • Ok thank you. I will try to implement this with iframe now. – wplearner Jun 01 '17 at 20:31