0

Any one help me. I have described the problem in the following lines.

I want to call the second.html with in one.html.

Inside the second.html ,I have included the second.js using script tag.

When I call the second.html in the browser(safari,chorme,firefox) directly,It works FINE.

But If I call the second.html inside the one.html then the second.js(cannot call by second.html) does not work.

Please Help me. I have attached the code. one.html

<!DOCTYPE html> 
<html> 
  <head> 
    <title>Page Title</title> 
    <link rel="stylesheet" href="jquery.mobile-1.0a2.min.css" />
    <script src="jquery-1.4.4.min.js"></script>
    <script src="jquery.mobile-1.0a2.min.js"></script> 
    <script src="Scripts/one.js"></script>
  </head> 
  <body> 

    <div data-role="page">
      <a href="Views/second.html" data-role="button" class="ui-btn-right">One</a>
    </div>

  </body>
</html>

Second.html

<!DOCTYPE html> 
<html> 
  <head> 
    <title>Sample </title> 
    <link rel="stylesheet" href="../jquery.mobile-1.0a2.min.css" />
    <script src="../jquery-1.4.4.min.js"></script>
    <script src="../jquery.mobile-1.0a2.min.js"></script>
    <script type="text/javascript" src="../Scripts/second.js"></script>
  </head> 
  <body>
    <div data-role="page">   
      <div data-role="button" id="link" >Second</div>
    </div><!-- /page -->
  </body>
</html>

one.js

$(document).ready(function()
{     
    alert('one.js');                    
});

second.js

$(document).ready(function()
{     
    alert('second.js');                    
});

THanks

4
  • 2
    How exactly do you "call the second.html"? Is it AJAX? Commented Dec 9, 2010 at 13:55
  • We need more info. Are they related in any way, like one.html as an iframe inside the second.html? Commented Dec 9, 2010 at 14:25
  • Hi All. I have attached the sample code. Please help me. Commented Dec 10, 2010 at 4:51
  • It's still not clear what you mean by "calling the second.html". You link to second.html from one.html, but that's not calling second.html by any meaning of "calling" I'm aware of. Also "it works" and "it doesn't work" tells us almost nothing; tell us exactly what you expect to happen and what actually happens. Read over "Writing the Perfect Question" for more on asking questions well. Commented Dec 10, 2010 at 5:21

2 Answers 2

1

From what I have read, jQuery mobile Ajax pages do not fire the ready event when the new content is displayed. You will most likely need to bind to the pagecreate event for all 'data-role="page"' elements, and check whether an id of an element on second.html is there.

The comments section of this documentation page has some potential fixes for this: http://forum.jquery.com/topic/mobile-events-documentation

Sign up to request clarification or add additional context in comments.

Comments

1

A link is just a reference to another page; the browser doesn't actually load it before you click it (as far as the scripts on the first page are concerned, anyway).

If you want to access scripts on another page, two conditions must be met:

  1. The two pages must come from the same domain (for security reasons).

  2. The two pages must be loaded in the same window (for example using an iframe).

Please post a new question asking what you want to achieve, maybe there is a different solution.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.