JavaScript problem in FF

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Dec 2006
Posts: 17
Reputation: pojke is an unknown quantity at this point 
Solved Threads: 0
pojke pojke is offline Offline
Newbie Poster

JavaScript problem in FF

 
0
  #1
Dec 27th, 2006
Hi,
I got very very strange problem. Since 19 of december, when all FireFox in company was upgrated automaticaly, code below stopped working. Strange thing is, when i wanted to solve it, it started to work when i've putted alert() function. Here you have working and not working examples. I'll add that this function is used about 4 times on the site:

NOT WORKING SCRIPT:
  1. function loadJSintoDIV(id, url, switchdiv) {
  2. obj = document.getElementById(id);
  3.  
  4. if(obj.innerHTML == '' || !switchdiv) {
  5. oelem=document.createElement("script");
  6. oelem.src=url;
  7. oelem.type="text/javascript";
  8. oelem.defer=true;
  9. document.getElementsByTagName("head")[0].appendChild(oelem);
  10.  
  11. obj.style.height = '';
  12. obj.style.visibility = 'visible';
  13. } else {
  14. obj.innerHTML = '';
  15. obj.style.height = '0px';
  16. obj.style.visibility = 'hidden';
  17. }
  18. }

WORKING SCRIPT:
  1. function loadJSintoDIV(id, url, switchdiv) {
  2. obj = document.getElementById(id);
  3. alert('test');
  4. if(obj.innerHTML == '' || !switchdiv) {
  5. oelem=document.createElement("script");
  6. oelem.src=url;
  7. oelem.type="text/javascript";
  8. oelem.defer=true;
  9. document.getElementsByTagName("head")[0].appendChild(oelem);
  10.  
  11. obj.style.height = '';
  12. obj.style.visibility = 'visible';
  13. } else {
  14. obj.innerHTML = '';
  15. obj.style.height = '0px';
  16. obj.style.visibility = 'hidden';
  17. }
  18. }

When press "ok" in alert popup, it works, without alert....crap...

Any ideas whats wrong?
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 1,091
Reputation: MattEvans is a jewel in the rough MattEvans is a jewel in the rough MattEvans is a jewel in the rough 
Solved Threads: 63
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Veteran Poster

Re: JavaScript problem in FF

 
0
  #2
Jan 2nd, 2007
Where, or if you prefer when, is this code executed?

To be precise, what event* do you use to execute the function?

I ask that because, (I'll go out on a limb here) the code may be being executed as the page loads, but (perhaps) the script can only function correctly when the page is loaded fully. Forcing you to answer a modal message box {via alert()} causes the execution of the remainder of the function to be temporarily paused, meaning that when the important parts of the function are executed, the page has loaded.

Like I hope that I implied, that's an assumption founded on a working knowledge rather than any practical tests or even directly related experience**. The easiest way to find out if this is the case is to try putting the alert() after the function's main body, and posting back what happens.

Also; do say where the code is called from/when it is called.

*'inside script tags' is a viable event of sorts.
**or infact, a complete understanding of what you're trying to achieve. If you're calling this function from a user invoked event (like a click) on a fully loaded page; I have no idea.
Last edited by MattEvans; Jan 2nd, 2007 at 3:59 am.
Plato forgot the nullahedron..
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 17
Reputation: pojke is an unknown quantity at this point 
Solved Threads: 0
pojke pojke is offline Offline
Newbie Poster

Re: JavaScript problem in FF

 
0
  #3
Jan 2nd, 2007
OK,

First of all, the function is loaded from *.js file.
Then it is called 6 or 7 times on one page by call like this:
  1. loadJSintoDIV('emailsList', 'crm_overview_emails.php?unique=emailsList&thr_id={$thr_id}&kon_id={$kon_id}&List_Eml_ID={$get.List_Eml_ID}', true); //code in {...} is Smarty
Now, first load of page. If the last parameter is true, div is still hidden. If false, div is loaded by appendChild(). Of course, later every part of page can be hidden and loaded by button, but it is working.
The problem is, that while page is loading 3 functions have last parameter false, so 3 parts normally was loaded. After last FF update only first is loaded, and other 2 is not.
Starting to work with alert, as i said...
Any ideas?
Last edited by pojke; Jan 2nd, 2007 at 5:35 am.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 1,091
Reputation: MattEvans is a jewel in the rough MattEvans is a jewel in the rough MattEvans is a jewel in the rough 
Solved Threads: 63
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Veteran Poster

Re: JavaScript problem in FF

 
0
  #4
Jan 2nd, 2007
what happens if you try this code:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function loadJSintoDIV(id, url, switchdiv) {
  2. obj = document.getElementById(id);
  3. if(obj.innerHTML == '' || !switchdiv) {
  4. oelem=document.createElement("script");
  5. oelem.src=url;
  6. oelem.type="text/javascript";
  7. oelem.defer=true;
  8. document.getElementsByTagName("head")[0].appendChild(oelem);
  9.  
  10. obj.style.height = '';
  11. obj.style.visibility = 'visible';
  12. } else {
  13. obj.innerHTML = '';
  14. obj.style.height = '0px';
  15. obj.style.visibility = 'hidden';
  16. }
  17. alert('test');
  18. }

Notice the movement of the alert() line. This isn't an attempt to solve your problem, but let me know if it has the same effect as having the alert() line first, or if there is a difference
Last edited by MattEvans; Jan 2nd, 2007 at 6:11 am. Reason: ahhh having probs with codetags and pasted code
Plato forgot the nullahedron..
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 17
Reputation: pojke is an unknown quantity at this point 
Solved Threads: 0
pojke pojke is offline Offline
Newbie Poster

Re: JavaScript problem in FF

 
0
  #5
Jan 2nd, 2007
With an alert at the end... not working...
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 1,091
Reputation: MattEvans is a jewel in the rough MattEvans is a jewel in the rough MattEvans is a jewel in the rough 
Solved Threads: 63
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Veteran Poster

Re: JavaScript problem in FF

 
0
  #6
Jan 2nd, 2007
what about the event that calls that function during loading? is it called like this:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <body onload="loadJSintoDIV(etc);">
  2. ...

or like this:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <script type="text/javascript">
  2. loadJSintoDIV(etc);
  3. </script>

or by some other means?
Plato forgot the nullahedron..
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 17
Reputation: pojke is an unknown quantity at this point 
Solved Threads: 0
pojke pojke is offline Offline
Newbie Poster

Re: JavaScript problem in FF

 
0
  #7
Jan 2nd, 2007
The second way :
  1. <script language="JavaScript">
  2. loadJSintoDIV('emailsList', 'crm_overview_emails.php?unique=emailsList&thr_id={$thr_id}&kon_id={$kon_id}&List_Eml_ID={$get.List_Eml_ID}', true);
  3. </script>
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 1,091
Reputation: MattEvans is a jewel in the rough MattEvans is a jewel in the rough MattEvans is a jewel in the rough 
Solved Threads: 63
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Veteran Poster

Re: JavaScript problem in FF

 
0
  #8
Jan 2nd, 2007
try the first way.

the second way executes at an arbitrary time (possibly as it is encountered and thus before the document is loaded); the first way executes when the document has finished loading.
Plato forgot the nullahedron..
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 17
Reputation: pojke is an unknown quantity at this point 
Solved Threads: 0
pojke pojke is offline Offline
Newbie Poster

Re: JavaScript problem in FF

 
0
  #9
Jan 3rd, 2007
Unfortunately i can't use straight the first way, its because every function call is in another file (p.e. mails in crm_mail.tpl, faxes in crm_fax.tpl, letters in crm_letters.tpl), so i need Smarty variables after <body> which is in _header.tpl (In one page is about 20 files loaded for whole system).
I can try change at the end document.getElementsByTagName("body")[0].onload but it needs reference to a function, so all 3 calls need to be put in one moment, and i'm not sure how long Smarty remember variables. I'll try...
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC