Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 5th Oct 2011, 10:09 PM   #1
Brian Kindsvater
War Room Member
 
Join Date: 2004
Location: Sparta
Posts: 4,084
Thanks: 153
Thanked 4,818 Times in 1,585 Posts
Blog Entries: 190
Default
JavaScript Not Work Unless Refresh Page
Share on: 
fb share twitter share gplus share more share

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.

.




.
kindsvater is offline  
Unread 6th Oct 2011, 04:51 AM   #2
VIP Warrior
War Room Member
 
Join Date: 2006
Location: , , USA.
Posts: 1,795
Thanks: 70
Thanked 287 Times in 259 Posts
Default
Re: JavaScript Not Work Unless Refresh Page
Share on: 
fb share twitter share gplus share more share

Have you checked the code at line 190? Something may be loading out of order.
Have you tried in FF?
Where is the site?
KirkMcD is offline  
Unread 6th Oct 2011, 07:05 AM   #3
HyperActive Warrior
War Room Member
 
lovenot's Avatar
 
Join Date: 2011
Posts: 129
Thanks: 2
Thanked 13 Times in 12 Posts
Default
Re: JavaScript Not Work Unless Refresh Page
Share on: 
fb share twitter share gplus share more share

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?

lovenot is offline  
Unread 6th Oct 2011, 08:48 AM   #4
Active Warrior
 
Join Date: 2010
Posts: 75
Thanks: 8
Thanked 8 Times in 7 Posts
Default
Re: JavaScript Not Work Unless Refresh Page
Share on: 
fb share twitter share gplus share more share

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.
jmartinez is offline  
Closed Thread


Bookmarks

Tags
javascript, page, refresh, work


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 12:13 PM.