0

I have two html files first.html and second.html. Both are using a file main.js. So lets pretend I am in the second.html and I want to change the window.location.href to first.html. But the same time, I want to call a function, which should be executed in the first.html file just after it is loaded from the second file. So how should I do this. How can I check, from which page the first.html file was called to load?

If I will use the following code,

$(document).ready(function() {...});

The function would be loaded every time, I load this page. But I want to execute the function just, when the page is loaded from the second.html file.

Hope you understand my question.

1
  • how do you load your second.html page from first.html page? Through a link or by js action? or vice versa Commented Jun 3, 2015 at 12:44

2 Answers 2

1

You can check the url of the page. window.location.href should get you the url, which you can determine which page you're in.

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

Comments

0

Okay so you want to load the function only when the first.html is loaded from second.html. You can use localstorage or cookies to store the name of the page.

then use an if statement to check if the cookie is equal let's say to your previous page name then load the function. Then reset the cookie/delete it. Local storage does similar things too but according to w3 schools, they are better than cookies. I don't trust that site much though.

Comments

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.