0

I recently had the idea to attempt to make a proxy all in front end html and js. I have realized from multiple attempts this is a dumb idea. The machine I’m making this for has a special program on the device that redirects a url to another url with a “Blocked URL Message” I had an idea and that was to create a middle man that would take your website request, redirect you to that page, and prevent the blockers redirect from happening. I have looked all over but I don’t think there is a way to inject code into a redirected page. The code I am trying to inject is this

window.addEventListener(“beforeunload”, (event) => {
    event.preventDefault();
});

I am very new to HTML and JS and I was wondering if this was a good idea or not. If I can’t figure this out I will go back to writing a web server and then using an iframe to render the contents of that proxy. But in sum, I need to know if one this code I mentioned will prevent a redirect and 2 if it is possible to redirect to a specified URL and inject this code into the html from the redirected page

Zachary
  • 532
  • 3
  • 12
  • Try checking this answer: https://stackoverflow.com/questions/15811079/stop-redirecting-in-javascript Then you can inject the HTML after you stop the redirect. – WizardOfOz Nov 23 '22 at 07:02
  • The code I am injecting is the stop redirect because the blocking device as mentioned in my answer redirects a blocked page to a “you have been blocked website” basically the structure I want is go to my website > enter url > inject code into the url to prevent redirects to the “blocked” page > redirect to url – Zachary Nov 23 '22 at 07:10
  • Aha! I understand now. According to this answer: https://stackoverflow.com/questions/58887698/stop-url-redirect-to-a-particular-url-using-js-jquery You can stop a page redirect to a specific URL but the user will receive an alert. Not sure if there's any other way. – WizardOfOz Nov 23 '22 at 07:14
  • But one last thing. Do you have a way to inject the HTML into the redirect. Remember that the url being redirected to is not owned by me so I can’t just edit the code from the backend – Zachary Nov 23 '22 at 07:17
  • I don't think you can inject any code into the redirect url unless you have access to the domain. – WizardOfOz Nov 23 '22 at 08:03

0 Answers0