drilkmops
drilkmops2y ago

✅ – drilkmops – 23-31 Apr 12

bro ive been doing js for like 6 years and I have never done this before. I make a POST request and get something like the response below. How do I fire that JS..?
<!DOCTYPE html>
<html>
<body>
<script>
var redirectUrl = "https://www.example.com";
var anchor = encodeURIComponent(window.location.hash);
if (anchor.length > 0) {
redirectUrl = redirectUrl.replace("", anchor);
}
window.location = redirectUrl;
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<script>
var redirectUrl = "https://www.example.com";
var anchor = encodeURIComponent(window.location.hash);
if (anchor.length > 0) {
redirectUrl = redirectUrl.replace("", anchor);
}
window.location = redirectUrl;
</script>
</body>
</html>
3 Replies
drilkmops
drilkmopsOP2y ago
Looks like I can use eval() or new Function and pass in the things in the script tag. Neat! So a solution would look something like this
const parser = new DOMParser();
const tempDoc = parser.parseFromString(htmlResponse, "text/html");
const functionToFire = new Function(doc.querySelector("script").textContent)
functionToFire()
const parser = new DOMParser();
const tempDoc = parser.parseFromString(htmlResponse, "text/html");
const functionToFire = new Function(doc.querySelector("script").textContent)
functionToFire()
reactibot
reactibot2y ago
This question has an answer! Thank you for helping 😄 If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/1095853856526708766
reactibot
reactibot2y ago
This thread hasn’t had any activity in 36 hours, so it’s now locked. Threads are closed automatically after 36 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/1095853856526708766 Question not getting answered? Maybe it's hard to answer, or maybe you asked at a slow time. Check out these resources for help asking a good question: https://stackoverflow.com/help/how-to-ask http://wp.me/p2oIwo-26