473,396 Members | 1,929 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problem with JavaScript closure.

dmjpro
2,476 2GB
Expand|Select|Wrap|Line Numbers
  1. var previous_obj = null;
  2. var previous_url = null;
  3. function loadPage(cur_obj,url){
  4. previous_obj.onclick = function(){loadPage(this,previous_url);}
  5. previous_obj.className = "header_inactivated";
  6. cur_obj.className = "header_activated";
  7. cur_obj.onclick = function(){};
  8. previous_obj = cur_obj;
  9. previous_url = url;
  10. window.frames['main_frame'].location.href = url;
  11. }
  12. function set(){
  13. previous_obj = document.getElementById("own_alerts");
  14. previous_url = 'own_alerts.html';
  15. previous_obj.onclick = function(){}
  16. document.getElementById('main_frame').style.width = (screen.width-30)+"px";
  17. window.frames['main_frame'].location.href = 'own_alerts.html';
  18. }
  19.  
Expand|Select|Wrap|Line Numbers
  1. <body onload="set()">
  2. <table width="100%" border="0" cellspacing="0" cellpadding="0">
  3.   <tr>
  4.     <td class="header_activated" onclick="loadPage(this,'own_alerts.html')" id="own_alerts" 
  5.     title="List of alerts sent by you">Alerts sent by you</td>
  6.     <td class="header_inactivated" onclick="loadPage(this,'others_alerts.html')" id="others_alerts"
  7.     title="List of alerts recieved by you">Alerts recieved by you</td>
  8.     <td style="border-bottom-style:solid;border-bottom-color:#000000;border-bottom-width:2px">
  9.     &nbsp;
  10.     </td>
  11.   </tr>
  12.   <tr>
  13.     <td colspan="3" class="full" style="height:7px;background-color:#BBBBBB"></td>
  14.   </tr>
  15.   <tr>
  16.     <td colspan="3" class="full" style="height:700px">
  17.     <iframe src="" frameborder="0" height="690px" 
  18.     name="main_frame" scrolling="auto" id="main_frame"></iframe>
  19.     </td>
  20.   </tr>
  21. </table>
  22.  
  23. </body>
  24. </html>
  25.  
Here previous_url is not getting cloned ... How can i save the previous URL and pass it to the onclick handler of TD?
Feb 25 '09 #1
1 1161
dmjpro
2,476 2GB
Now it has been solved ;)
Actually it was happening due to global reference ...
I changed the code like this ...
Expand|Select|Wrap|Line Numbers
  1. function loadPage(cur_obj,url){
  2. var temp_url = previous_url;
  3. previous_obj.onclick = function(){loadPage(this,temp_url);}
  4. previous_obj.className = "header_inactivated";
  5. ......
  6. ......
  7. ......
  8.  
Feb 25 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Covad | last post by:
Hi all, For some reason my change() function is only called when the page loads. I'd much rather it gets called when the select changes. Here's the code: window.onload = init; function...
10
by: Emre Sevinc | last post by:
Take a look at the following snippet: <html> <head> <script> function add(elementId) { var container = document.getElementById(elementId); for (var i = 0; i < 10; i++) { var elt =...
10
by: lkagan2000 | last post by:
I'm reading 'Ajax in Action', (one of the best of the many tech books I've read) and there's an example that I just don't fully understand. If you happen to have the book, it's on page 75. I'm...
7
by: abs | last post by:
Hi everyone. Please, check my test code here: http://skocz.pl/jstest . The trouble is that no matter which span element I click, it alerts '3' and I'm wondering why not '1' for the first span,...
10
by: Evan Charlton | last post by:
Hey all, I'm having some trouble with window.setInterval() within a custom object/prototype. Here is my code: function MyClass() { // do some junk // ... // define methods this.m_one =...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.