Why is a function in Javacript not called when loading new page by clicking href url?
-
I have a problem with the href link and my javascript code. Here is my javascript code in my âdex.htmlâdex.htmlindex.html and curate.htmlcurate.htmlcurate.html: $(document).ready(function(){ alert("Hello!"); }); In the html code, it's just code of a navigation bar: <ul> <li><a href="index.html">Home</a></li> <li><a href="curate.html">curate</a></li> </ul> So the problem is: when I on the home page, for instance, click the curate link to the curate page, the alert will not pop out. It seems the function is not called in javascript. However, it works if I reload the curate page. Same problem from the curate page to the home page. The problem will be fixed if I change the html code as <ul> <li><a href="index.html" >Home</a></li> <li><a onclick="gotoCurate()">curate</a></li> </ul> and add the js code in index.html: function gotoCurate() { window.location="curate.html" } Similar to the curate page. I guess maybe when using href, the page isn't really load. I add `<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">` in the head but it doesn't work. For some reasons I would like to use href to direct between the pages. So does anyone know how can i fix the problem while keeping the href links? Thanks!
-
Answer:
An anchor tag without a href attribute is not safe. First, without an href attribute, it will not be a link. If it isn't a link, it won't be a keyword. Second, you should have an alternative for when the JavaScript doesn't run. Take a look at this http://jsfiddle.net/wCLAx/6/. You might be wrong. I just tested this with chrome. Both of them work fine except for the unsafe condition where the href attribute is not defined in one of the cases.
Boopathi Rajaa at Quora Visit the source
Related Q & A:
- How to pass a parameter to a function that is called on an event?Best solution by Stack Overflow
- How do I delete my old Yahoo page after I made a new page?Best solution by answers.yahoo.com
- What is it called when you have a hard bump on your heal?Best solution by Yahoo! Answers
- What is it called when you don't have a knuckle?Best solution by Yahoo! Answers
- Why does a nose run when you have a cold?Best solution by thesurvivaldoctor.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.