0

I have created 2 static html pages locally, demo1.html and demo2.html.

I need to redirect from one page to another pag. Initially I opened my demo1.html page (url is file:///D:/app/demo1.html).

Now on clicking a button in this page I want to redirect to demo2.html

I tried:

$( "#submit" ).click(function() {
    window.location.href = "/demo2.html";
});

but it did not work. What changes I need to make it to work?

6
  • 2
    So what is your problem? Commented May 18, 2015 at 16:43
  • What errors do you get? Did you load jQuery (which seems like overkill for a redirection)? Commented May 18, 2015 at 16:48
  • 1
    Are the two pages in the same place? Try removing the "/" from your address: "demo2.html"; Commented May 18, 2015 at 16:48
  • Yes ,its in same place, I tried removing "/" did nit work. no action happens. I have loaded jquery and this function is written on ready function Commented May 18, 2015 at 16:51
  • can you post your demo1.html Commented May 18, 2015 at 17:00

2 Answers 2

3

Drop the / at the begining of your new url.

If you are loading from a file like you said, writing "/demo2.html" will map to file:///d:/demo2.html

If you write

 $( "#submit" ).click(function() {
     window.location.href = "demo2.html";
 });

This will map to the same folder where you started your app, that is file:///D:/app/demo2.html

Sign up to request clarification or add additional context in comments.

2 Comments

Did not work, it just adds "?" to th url , no redirection happens
I just tested the code an it works. If is not working for you is because you are not showing the full example. I recommend you that you post the demo1.html code (Maybe you are using another framework????)
0

Try this

 $('#submit').click(function() {
     window.location = '/demo2.html';
 };

1 Comment

Did not work, it just adds "?" to th url , no redirection happens

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.