Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7806817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:39:15+00:00 2026-06-02T02:39:15+00:00

I have this code: <html><head></head><body> <script language="javascript" type="text/javascript"> function f(){ //WHAT I HAVE TO

  • 0

I have this code:

<html><head></head><body>
    <script language="javascript" type="text/javascript">
        function f(){
             //WHAT I HAVE TO PUT HERE?
        }
        function unloadFCT() {
             //CODE WHEN THE WINDOW IS UNLOADED
        }               
        var val = navigator.userAgent.toLowerCase();
        if(val.indexOf("msie") > -1){
             window.attachEvent('onbeforeunload', unloadFCT);
        }
        else{
             window.onunload = unloadFCT;   
        }
</script>
<a href="#" onclick="f()" >Call unloadFCT() function</a>
</body></html>

The goal of f() is to execute the code of unloadFCT().

Who can tell me what’s the code of f()?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T02:39:17+00:00Added an answer on June 2, 2026 at 2:39 am

    /***********test1.php**********/
    I create a simple example to understand the problem, Bellow is the content of test1.php file

    <html><head></head><body>
    <script language="javascript" type="text/javascript">
    var xhrHttp;
    function getXHRObject() {
       var obj = false;
       try {
          obj = new ActiveXObject("Msxml2.XMLHTTP");
       }
       catch (e) {
          try {
             obj = new ActiveXObject("Microsoft.XMLHTTP");
          }
          catch (e) {
             try {
                obj = new XMLHttpRequest();
             }
             catch (e) {
                return false;
             }
          }
       }
       return obj;
    }
    function unloadFCT() {
        xhrHttp = getXHRObject();   
        xhrHttp.open("GET", "ajaxCall.php", false);
    }       
    
    var val = navigator.userAgent.toLowerCase();
    if(val.indexOf("msie") > -1){
        window.attachEvent('onbeforeunload', unloadFCT);
    }
    else{
        window.onunload = unloadFCT;    
    }
    

    When you close this window, a new file will be created in the same place as ajaxCall.php

    /***********ajaxCall.php**********/

    <?php
        $handle = fopen("myFile_".time().".txt", 'a+');
        fwrite($handle, "simple message..."); 
    ?>
    

    /***********test2.php****/

    <html><head></head><body>
    <script language="javascript" type="text/javascript">
    var xhrHttp;
    function f(){
        unloadFCT();
        window.close();
    }
    function getXHRObject() {
       var obj = false;
       try {
          obj = new ActiveXObject("Msxml2.XMLHTTP");
       }
       catch (e) {
          try {
             obj = new ActiveXObject("Microsoft.XMLHTTP");
          }
          catch (e) {
             try {
                obj = new XMLHttpRequest();
             }
             catch (e) {
                return false;
             }
          }
       }
       return obj;
    }
    function unloadFCT() {
        xhrHttp = getXHRObject();   
        xhrHttp.open("GET", "ajaxCall.php", false);
    }       
    var val = navigator.userAgent.toLowerCase();
    if(val.indexOf("msie") > -1){
        window.attachEvent('onbeforeunload', unloadFCT);
    }
    else{
        window.onunload = unloadFCT;    
    }       
    

    Execute the code of unloadFCT() function and close this window!!!

    /*************Problem***********/

    Can you please tell me what’s wrong in test2.php? I want the f() function to execute the code of unloadFCT() and close the current window.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, I have this code: <html> <head> <script type=text/javascript src=http://code.jquery.com/jquery-1.7.1.min.js></script> <script type=text/javascript> function get()
I don't understand this, I have this code: <html> <head> <title>Problema</title> <script language=javascript type=text/javascript
OK i have this code HTML: <html> <head> <script type=text/javascript src=http://code.jquery.com/jquery-1.7.1.min.js> </script> <script type=text/javascript>
I have this html code <html> <head> <title>JQuery Problem 2</title> <script type=text/javascript src=jquery-1.4.min.js></script> <script
i Have this code that select all checkboxes: <html> <head> <script language=javascript> function checkAll(){
I have a JavaScript function, in this function i will write <script type='text/JavaScript' language='JavaScript'>alert('ha')</script>
i have this code: <!DOCTYPE HTML> <html> <head> <script src=http://ajax.googleapis.com/ajax/libs/dojo/1.7.1/dojo/dojo.js type=text/javascript djConfig=parseOnLoad: true></script> <script
I have an application that contains this code: <script src=Scripts/jquery-1.4.1.min.js type=text/javascript></script> <script src=Scripts/facebox.js type=text/javascript></script>
Let's say I have some code like this: <html> <head><title>Title</title></head> <body> <?php if (!$someCondition){
When I'm trying to run the following code in IE:- <html> <head> <script language=javascript>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.