开发者

Call - Javascript Function

开发者 https://www.devze.com 2023-01-30 06:16 出处:网络
Any one help me. I have described the problem in the following lines. I want to call the second.html with in one.html.

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


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


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.

0

精彩评论

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