javascript - Loading other pages using JQuery -


if project contains 2 html pages, let's call them page1 , page2 , in page1 have link page2 , in page2 have jquery file needs access page1 , check if link page2 pressed (to stuff) how implement this?

here i've tried: jquery file on page2

 $(document).ready(function () {      $(this).load("page1.html"); // loads page1 current page - page2         $("#link").click(function () { //if link on page1 pressed, stuff              //todo 

but doesn't work. solutions?

as @dvenkatsagar commented, use control variable global.

the .load() method has callback function can pass parameter. have stuff inside callback. also, append contents of "page1" "page2" must use element, not document itself. check out docs: http://api.jquery.com/load/.

$(document).ready(function () {       // declare control variable     var clicked = false;      // loads page1 current page - page2     $("#mydiv").load("page1.html", function(){           //if link on page1 pressed, stuff         $("#link").click(function () {               // set control variable true             clicked = true;          });     });   }); 

Comments