JavaScript Not Work Unless Refresh Page

3 replies
I am replacing html links on an auto generated site with JavaScript links on the fly and writing the JavaScript the links to an external file.

So my web pages have a JavaScript onclick function that is using the link in the external file.

Sometimes when the pages are loaded the links work fine.

Sometimes they do not. Nothing happens. But after refreshing the page, and thus writing to the external file twice - then they work.

Similarly, if I fopen the external file using the 'w' command to reset it, and then write the links to it, the web page links do not work.

But if I refresh the web page then they work again.

Any ideas?

---

Using Internet Explorer when the link does not work I get this error code:

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)
Timestamp: Thu, 6 Oct 2011 04:06:34 UTC


Message: Object expected
Line: 190
Char: 1
Code: 0
URI: http://[my web page]


Refresh the page, and the error goes away and the link works fine.

.




.
#javascript #page #refresh #work
  • Profile picture of the author KirkMcD
    Have you checked the code at line 190? Something may be loading out of order.
    Have you tried in FF?
    Where is the site?
    {{ DiscussionBoard.errors[4819708].message }}
  • Profile picture of the author lovenot
    If you are using external javascript libraries like jquery, have you tried loading them first before you loaded your scripts which make use of the library?
    {{ DiscussionBoard.errors[4820270].message }}
  • Profile picture of the author jmartinez
    It's hard to tell from the brief description, but if you haven't already, be sure to load your javascript after the dom loads. Most framewoks will have an onDomReady function for this purpose. You can also set it up without using a framework by executing your code in the right place.

    If you are getting errors it could be your script is breaking before everything loads since code is trying to access something that doesn't exist.

    Here is a link to jquery that explains it a bit.
    {{ DiscussionBoard.errors[4820847].message }}

Trending Topics