How to call Javascript function from another page?

I have 5 javascript index.php functions:

1) showMsg(); //this display 50 latest messages

2) showPopUpBox(); // this I use jquery to load the textbox and send button from typingMsg.php

3) hidePopUpBox(); // this hide pop up box

4) checkNewMsg(); // this will be auto reloaded every 5 sec to check if there is new message, it will show the numbers counts of total new messages.

5) ShowNewMsg(); // this function will be called when the user click the "show new messages" button.

After the user enters the message in the text box in the pop-up window, after clicking the "Send" button, ajax will call messagePost.php to send the message to the database in the form of the following code:

$(function() {
$(".button").click(function() {
$.ajax({
             type: "POST",
             url: "messagePost.php",
             data: dataString,
             success: function() {
                 $('textarea.expand25-75').val('');
                 showMsg(); //this is my problem
                 hidePopUpBox(); //this is my problem too
             }
        });
    return false;
});
});

As you can see from the above codes, the showMsg () function; hidePopUpBox (); cannot be called because functions are not on this page, my question is: how to call a javascript function from another page?

+3
source share
5 answers

You will need to include all the functions that you need on each of the pages that will use them (index.php and messagePost.php, I think).

.js, <script>.


, , , top opener. , .

, hidePopUpBox() ( , ), .

+2

top.showMsg();
top.hidePopUpBox();

top window . iframe, .

opener, ( window.open)

opener.showMsg();
opener.hidePopUpBox();
+2

, , script , .

$(function() {
$(".button").click(function() {
$.ajax({
             type: "POST",
             url: "messagePost.php",
             data: dataString,
             success: function() {
                 $('textarea.expand25-75').val('');
                 opener.showMsg(); //this is my problem
                 opener.hidePopUpBox(); //this is my problem too
             }
        });
    return false;
});
});

opener , , .

+1

" "? index.php, . , jQuery, javascript $(Document).ready(function() { });

, , .

0

no no , , ,

$(function() {
// You Are Here Not in contact with outside script 
});

, javascript ,

window.onload=function()
{  
 $(".button").click(function() {
     $.ajax({
             type: "POST",
             url: "messagePost.php",
             data: dataString,
             success: function() {
                 $('textarea.expand25-75').val('');
                 opener.showMsg(); //this is my problem
                 opener.hidePopUpBox(); //this is my problem too
             }
        });
    return false;
});
}

0

All Articles