Reputation: 167
I am trying to redirect to a different page from a function using HTML and Javascript. When I hardcode the URL it gets redirected, but when I put it in a variable it does not. please help.
I am using node version 8.x
function p(){
var c ="abc.com";
var e = `
<script type="text/javascript">
function Redirect(){
window.location=${c};
}
document.write("wait");
setTimeout('Redirect()', 1000);
</script>`
return e;
};
Upvotes: 1
Views: 78
Reputation: 29339
You need to change two things
add quotes around your passed page name
and remove quotes and parentheses from the timeout callback function
...
window.location="${callback}";
...
setTimeout(Redirect, 5000);
....
Upvotes: 2