JavaScript - Force Browser To Close And Reopen.
Hi, I am new here, it's nice to meet you guys.
I am writting a javascript that need to force the user to close the current browser and then restart automatically again after some operation. Here is the case : The user will retrieve a file from the server and save it in the local drive. After that, the browser will automatically open the .pdf saved with the browser(IE) but not Adode reader. If the user wants to update the previous saved .pdf in the local drive, they will need the user to close the opened file(saved .pdf) so that new updated .pdf can be replaced to the old .pdf file. So, I need to implement a function that force the browser to close, then copy and replace the old file, then reopen the file(new and updated) again. Is there any possible way of doing this ? Please provide me some idea. I have tried to look for informations online but I just got no luck. Failed with the coding provided. Thanks in advance. P/S : The file need to be closed in order to replace it with a new one. The platform using is Windows. Similar TutorialsI have an emagazine i want to add to my website, the probelm is when it opens in a browser you have to sroll down the page, to view it all, what i was wondering is, is it possibe to create a link that when somebody selects to view the magazine it forces the browser to openin full screen mode so that it fits niely on the screen without the toolbars and evertything taking up half the page. Thanks Hi folks, I've got a chat program which relies on a column in a MySQL database to see if he/she has logged out or not. But if you close the browser window, the computer still thinks you're online. I wrote this in the JavaScript section cos I think it would definitely need Javascript. So any help for updating the database in any way? Thanks!! Lucas In my application I want user to take an "Exit Survey"(Independent website) when he is leaving the application. As name explains, It should happen only when user closes current browser tab or browser window. Its possible using JavaScript OnUnload event. But the problem is that this event occurs on 1. close of browser tab 2. close of browser window 3. click of any internal page link(i.e anchors and form buttons) 4. click of browser's Refresh button 5. click of browser's Back/Forward button I have handled first 3 cases but not able to detect Refresh and Back/Forward button click. Has anybody of you implemented such functionality?? Thanks in advance!!! function doUnload() { if (window.event.clientX < 0 && window.event.clientY < 0) { alert("Window is closing..."); } } i get window.event undefined by using var evt =window.event? event : e i get e undefuned var evt =window.event? event : e if (evt.clientX < 0 && evt.clientY < 0) { alert(evt.clientX +"Window is closing..."); } Hi! I need to open a window when: 1 user leaves the site 2 when the browser is closed. I tried the 'unLoad' event but it works only for the user leaves site case and not the browser close. Here is the code I tried: <html> <head> <title>Detecting browser close </title> <script type="text/javascript"> function doUnload() { myWin= open("exit_site.php", "exitWin", "width=50,height=50"); } </script> </head> <body onunload="doUnload()" <h4>Close browser!</h4> </body> </html> Neep your help, please i used the code window.close(); it works well for Internet Explorer but it not worked in firefox Hi, i have an popup which is an aspx page and when i click on browser close button..., the system should check if there is any unsaved data in the form or not. If there is any unsaved data then the message should be displayed (Do you want to leave..?) with OK and Cancel button... On click of the OK button, the data should not be saved and the user should be returned parent form ie popup should be closed and return to the parent form.On click of the cancel button, the control should return to the Pop. I had tried the below code... window.onbeforeunload = close; function close() { var result=confirm("Do you really want to close this window"); if (result) { return true; } else { location.href = document.URL; } } The above code is not working ie the popup is getting closed even on click of closse button.... and when clicked on OK it is dispalying another msgbox with leave this page and Stay on this page buttons... Please help me regarding the same... Hi, I need to display alert when I close the browser window. Now I am using the following code to display the alert. But the alert is getting displayed even I click on any links. But the alert should not displayed when i click the link. If you have any solution, please let me know. Thanks in advance. This is my code: <HTML> <head> <script> function closeIt() { return ""; } window.onbeforeunload = closeIt; </script> </head> <body> <a href="http://www.test.com">Click here to navigate to www.test.com</a> </body> </html> -------------------------------------------------------------------------------- I am currently using onbeforeunload to show user a message 'click ok to save, cancel to continue' Question.. On browser close event (user clicks on window close button 'X' on browser), I do not want to show the message to user. Can you please help with how to check the browser close event. Other details.. If user closes the browser, my ajax request is not getting executed and hence I am not able to save the data to database. Hence I am planning not to show the popup when user closes the browser. Thanks in advance... Sandip Hi... Is there anyway to differentiate between refreshing a window and closing the browser. It seems both events are handled by onUnload event. Thanks We have a testing application that displays a timer on the screen using Javascript. It seems to be working very well. However, someone brought to my attention today that if you click-and-hold the browsers close button in the upper right corner (the X button in Windows) that the timer will stop. You can then slide your mouse cursor off of the button, and the browser will not close, but the timer was stopped for the entire time that the button was being held down. This also works for the Minimize and Maximize buttons. Is there any way at all to take care of this problem? Thanks, Jesse Hi , Kindly help I have to handle the browser RED X close button in the window. The problem is that its not saving the data. before submitting/saving the data it executes the window.close() I put settime out and form on submit conditionalyy put even its not saving the data But window is closing. how can we sequentiate the save + window.close() im copying the code below. ============ window.onbeforeunload = function() { if (window.event.clientY < 0 && (window.event.clientX > (document.documentElement.clientWidth - 5) || window.event.clientX < 15)) { editedCheck(); document.BuildRequestForm.buttonClicked.value="REDX"; if( document.BuildRequestForm.measdatachanged.value=="false") { setVarZero(); fn_Close(); } else { if(confirm('Do you want to save the changes?')) { elmtForm.onsubmit = fn_Close; //document.BuildRequestForm.onsubmit=fn_Close; //setVarZero() saveMeasurement(); setTimeout('setVarZero()',1000); //window.setTimeout(function() { window.close();}, 1000); //window.setTimeout(function() { fn_Close();}, 1000); //fn_Close(); //return true; } else { return "If you want to close the window click - Leave Page";} } } } ============= browser close RED X button+ popup OK Cancel "save or not" +OK Hello! I am trying to find a script that allows you to open multiple browser tabs and then close each of those tabs, either one by one or all at once. Does anyone know how to do this please? Thanks so much for your help. Hi! I'm new to this, so please bare with me. My terminology may not be up to par. Here's the deal: - I have a button on my Flash site that opens an HTML page in a popup window. In Flash, I open the new window using Actiosnscript 2.0: Code: on (release) { getURL("example1.html", "_blank"); } - Within the popup window are links to other HTML pages. They all open in the same window. I've been using the following to create the links in Dreamweaver: Code: onClick="MM_goToURL('parent','example2.html')" - On each page, I have a "Return to Main Menu" button that should close the popup window. To do this, I have been using: Code: onClick="window.close()" - The problem is that it works differently in each browser, and I can't even get it to consistently close the window in most browsers: Internet Explorer = popup message appears, asking "Are you sure you want to close this window?" or something similar; window closes after clicking "Yes." Safari = Only closes if I'm on the original HTML page. If I click on any of the other links (note that these all open in the same window), those pages' "Return to Main Menu" buttons cease to work. However, if I keep clicking "Back" until I get to the original page, it closes. Opera = Button actually works for each page. Firefox & Chrome = Does not close the window at all. I looked into it and saw that others have used a window.opener to solve similar issues. But, since my popup window is opened using Flash/AS2, I need to find a way around it. I've tried preceding "window.close()" with "window.opener=null" (i.e. - onClick="window.opener=null; window.close()"), but I don't think I'm doing it right because it still doesn't work. I've also seen others use codes that involve functions and variables, but it is beyond my current coding knowledge to implement this. Like I said, I'm sort of new at this. Any advice would be greatly appreciated. Thank you. - PW Hey I want to enforce a click on the facebook share button, please help me out here. I was thinking something like this: Code: javascript:window.location="http://www.facebook.com/connect/prompt_feed.php?locale=en_US&message=hi"; javascript:function selectFirst() { publish.focus(); publish.click();} selectFirst(); Something wrong with that code? What code would work? Is it not possible? Thanks a lot, Sarah Hi all, I have a script that validates a postcode, including checking that the 4th character from the end of the postcode is a space. To save sending you back to the postcode textbox to correct the error, how can I automatically force a space at the 4th character position from the end of the postcode? ie, CM12JB is wrong. Need to change it to CM1 2JB. Any ideas? Gary We got our image view situation about 95% figure out, but need one last thing. How can we tell the image viewer to display 1 thumbnail, no matter the case? When a product only has one picture, as opposed to 2-4, there is no thumbnail associated with the main image. We would like to have one thumbnail appear no matter the case, as it fits in with page design. Anyone know how to edit the code to do this? If you want a link to check it out on our site, please pm or email me. Here is the javascript. Code: <script language="javascript"><!-- //thumbnail script var image1,image2,image3,image4,selectedimage; var imagemaxwidth, imagemaxheight imagemaxwidth=[image_medium_w]; imagemaxheight=0; image1="[image1]"; image2="[image2]"; image3="[image3]"; image4="[image4]"; imagecaption1="[imagecaption1]"; imagecaption2="[imagecaption2]"; imagecaption3="[imagecaption3]"; imagecaption4="[imagecaption4]"; selectedimage='[image1]'; //pre load image1 zoom_enable=[3dzoom_enabled]; //0 = zoomify | 1 = magiczoom function image_click(clicks) { if (document.getElementById('listing_main_image_link')!=undefined) { if (zoom_enable==1) { selectedimage=eval('image'+clicks); MagicZoomPlus.update('listing_main_image_link', selectedimage, 'thumbnail.asp?file=' + selectedimage + '&maxx='+imagemaxwidth+'&maxy='+imagemaxheight, 'show-title: false'); changecontent("imagecaptiont",eval('imagecaption'+clicks)); document.getElementById('listing_main_image_link').href=this.name; }else { selectedimage=eval('image'+clicks); document.getElementById('large').src='thumbnail.asp?file=' + selectedimage + '&maxx='+imagemaxwidth+'&maxy='+imagemaxheight; document.getElementById('listing_main_image_link').href='#'; document.getElementById('listing_main_image_link').onclick=zoomify_popup; changecontent("imagecaptiont",eval('imagecaption'+clicks)); }} } function zoomify_popup() { popupsimple('zoomify.asp?catalogid=[catalogid]&img=' + selectedimage ,500,500); } function check_stock(what,partnum) { var soption; var i; var product_availability='[availability]'; var backordermode='[allowbackorder]'; var avail_instock='[productAvailability-Instock]'; var avail_outofstock='[productAvailability-Outofstock]'; var avail_backorder='[productAvailability-Backorder]'; var optionfound=0; if (inventoryarray[catalogid].length==0) //if there is no advanced options, don't look for stock { return true; } else { for(i=0;i<inventoryarray[catalogid].length;i++) { soption=inventoryarray[catalogid][i]; field_array=soption.split("-"); //Dynamic Part for advanced options if (typeof((idarray[catalogid])) != "undefined") { soptionid=idarray[catalogid][i]; aoprice=aopricearray[catalogid][i]; if (field_array[0]==partnum) { if (soptionid != '') changeid(soptionid); if (aoprice != '0') changeprice(aoprice); } } if ((field_array[0]==partnum)) { changecontent("product_inventory",field_array[1]); if (eval(GetValue(what,"qty-0"))>field_array[1]) { optionfound=optionfound+1; if (backordermode==1) { changecontent("availability",avail_backorder); return true; optionfound=optionfound+1; } else { changecontent("availability",avail_outofstock); alert("The options you selected are not currently available."); optionfound=optionfound+2; return false; } } } } if (optionfound==0) { changecontent("availability",product_availability); return true; } if (optionfound==1) { changecontent("availability",avail_instock); return true; } } } function add_wishlist() { document.add.action = "add_cart.asp?action=addWishList"; document.add.submit(); } function add_giftregistry() { document.add.action = "add_cart.asp?action=addGiftRegistry"; document.add.submit(); } function check_and_add(formx) { if (document.add.std_price==null) { document.add.submit(); } else { var readytoadd=validateValues(formx,1) if (readytoadd==true) { document.add.submit(); } } } // --></script> Hey everyone. I am looking to enforce the use of 3 decimal places in an input. I have found some scripts that do this, however, I also want to format it this way in case someone enters LESS than 3 decimal places. If a user enters 1.25, I want it formatted as 1.250 If a user enters 1 I want it formatted as 1.000 etc. Possible? Not sure where to start. i want the scrollbars to be preset at the bottom of the div each time someone visits the site. Code: <div id="scroller-shoutbox" border="0" cellspacing="0" style="background-image:url(images/table-bg.png);border-bottom:solid 1px #333; width:498px; height:300px;border-left:solid 1px #333;border-right:solid 1px #333; overflow-x: hidden; overflow-y: auto;"> <table border="0" cellspacing="0" width="500"> <tr><td></td></tr> <!--- PHP array here in actuallity, but i figured it wasnt relevant to this post ---> <tr><td></td></tr> </table> </div> you can see the problem i am talking about here http://tomhilsee.com/ipool/index.php the latest content is unseen because the scrollers are at the top |