开发者

Document.ready script not working when page called into a tab

I have several pages that are called onto an ajax tabbed area. the pages that are called have javascript on them however the document.ready function will not load for each of these pages when loaded onto the tab. Instead I have had to put a button on the pages to load the function manually. Iv tried putting the document.ready function on both the page being called and the pages calling it but it still wont run. Is there any other way i can use rather than having a button? I dont want buttons displaying on my pages that have to be clicked before it looks good =(

Heres the code that calls the the page:

onclick="createNewTab('dhtmlgoodies_tabView1','Remote Access','','RemoteAccess.html',true);return false">Remote Access

All the javascript files are connected to the main page.

A button is located on the remoteaccess page:

input type='button' value='Load.' onclick='loadlightbox()'

The loadlightbox function is inside a javascript file that is conected to the main page:

loadlightbox = (function() {
    $('#gallery a').lightBo开发者_Python百科x({fixedNavigation:true});
});


There is no document.ready event being fired when you load the content into the page with JavaScript. Most libraries just stick what is returned with innerHTML. Most libraries just rip out the JavaScript code from the responseText and run it through eval().

You probably want to forget the whole document.ready and just stick the code block at the end.


The document.ready function won't fire because the page (document) is already loaded. The remote page is loaded as content not as a document.

Since you are using jquery you should take advantage of the .load function and also you should take a unobtrusive approach to attaching the onclick to your link. This allows your JS and code to be separate.

//Using Jquery load 
$("#id_of_link").click(function(e){
     e.preventDefault();
     $('#dhtmlgoodies_tabView1').load("RemoteAccess.html",
     function(){
          //callback code here
      })
})
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜