3

I have a variable defined in my script code that says:

    <script>
...
       var Path = "~/LogInfo.aspx" + ID;
...
    </script>

And I want to be able to use this variable in my html code:

<meta http-equiv="Refresh" content="3; url='Path'">

How would I do this?

6
  • 3
    You can't. You'd need to set the content attribute via JavaScript after the page is rendered. Commented Mar 13, 2014 at 23:00
  • 1
    What do you mean? I don't know much about web development yet Commented Mar 13, 2014 at 23:01
  • stackoverflow.com/questions/710275/… Commented Mar 13, 2014 at 23:04
  • stackoverflow.com/questions/2568760/… Commented Mar 13, 2014 at 23:06
  • Do you have jQuery available? Commented Mar 13, 2014 at 23:07

1 Answer 1

3

The meta refreshes are only read at page load. If you add one after page load, or try to change one after page load, it will not work. So you can't do it with Javascript because javascript runs on the client, after page load. So you have to set the path on the serverside. If you need logic to determine between different possible paths, it will have to be on the server with a server-side language.

Example with JSP:

 <%
 int x = pullXfromSomewhere();
 String path = "index" + x + ".jsp";
 %>
 <meta http-equiv="Refresh" content="3; url='<%=path%>'">
Sign up to request clarification or add additional context in comments.

2 Comments

If I need the path to contain info from the url how would I do this?
Do you mean from the querystring? like http://server/index.jsp?id=5 you want to use that id. Something like path = "index" + request.getParameter("id") + ".jsp";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.