JavaScript - How To Access Context From Javascript:onunload()
I am a relative javascript newbie. I wish to detect when a user is leaving a page, and want to know what s/he is doing to leave that page (browser BACK vs. clicked URL), and would like to be able to get this information from the ... document? Where is it held? How can I know this from within my script?
Thanks Eric Similar TutorialsUsing onclick=window.open function in js to open a pdf file link in a new popup window. Works fine to display the file onscreen, but not if the user wants to save the file client-side to their computer. The right-hand-button context menu for the mouse will allow the user to download, but the file saved will be a html dump file for the webpage and the name of the file will be that for the webpage. Of course I can use the easy <a href> method for download links and the mouse context menu options will be as expected, but I can only use target="-blank" or target="_self" . I need a popup window to open. Could use : oncontextmenu="alert('Left click the link to open, and then SAVE from with the pdf viewer') to advise users how to save the file, and could use "javascript: void(0)" to eliminate most mouse context menu options, so the user won't bother try. So how can I get a link to a file which can be viewed in a popup window and downloaded using mouse right-hand context menu? Any advice massively appreciated! -------------------------------------------------------------------------------- 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, I have the following code snippet: test.html ====== <script language="javascript" type="text/javascript"> var testVariable = "test"; </script> <script language="javascript" type="text/javascript" src="test.js"> </script> test.js ===== var testVariable = window.top.testVariable; In firefox, I'm able to access testvariable defined within test.html in test.js. But in chrome, test.js couldnot get the window.top.testVariable field defined in test.html. Can any one please let me know how i can make it work in chrome?. Am i missing something here?. hi, i want to make an ftp access page using javascript i know it's possible using "ftp://" , but when i use this, the browser loads a window with the ftp folder i want a javascript to get ftp access and to give the commands itself any1 who knows how to get ftp access and ability to give file send/receive/... commands with javascript? Hi someone please let me know the way to access a smarty value with javascript? my smarty value is = {$value.url} i want to access it like Code: <script type="text/javascript"> function load() { document.location = '{$value.url}'; } </script> i tried with wrapping code with {literal} {/literal} but it isnt working. can some one correct this please sorry for bad english Thanks Hi all, Have problem from getting data of JavaScript Object ie. Associative Array. Code: var a, table1 a = new ActiveXObject("MyProgID"); a.GetDataFromExcel("C:\\Users\\myFolder\\Desktop\\test.xls","Sheet1") a.Generate() table1 = a.writeInTable(); Here writeInTable function returns a 2D Object array from DLL written in VB.Net. So I got the Object to table1. But from table1, I can't access the values but its there. table1 shows values as in this image(Image Attached.) Actually, I tried many ways like tab(0)(0) tab[0][0] tab["0"] tab.(0).(0) tab.[0].[0] Also with toArray(), (new VBArray(tab)).toArray().... I don't know what I am wrong..Can anyone help me on this? Thanks... Shanmugavel.C Hi, I want to access SQL database using javascript. I am passing 1 value to the java script but I want to pass that value further to the SQL query as an where clause parameter to retrieve data. If the value retrieves multiple or single data then how do i handle it. Is it possible to use dataset in javascript? Regards, Anthony. Hello everybody, I am new in this forum (and I'm also new in web coding, but not in programming)... This is the first problem I met: I can't understand how to acccess a property in this snippet: Code: function FGGE() { this.totalExternals = 0; this.loadedExternals = 0; this.loadImage = function(image) { image.onload = function() { alert("Loaded 1: "+this.loadedExternals+"/"+this.totalExternals); }; alert("Loaded 2: "+this.loadedExternals+"/"+this.totalExternals); }; } Output is this: Loaded 1: NaN/undefined Loaded 2: 0/0 Could someone help me fixing "Loaded 1"? Thanks a lot Hi, I'm very new to javascript and I need your help. What I'm trying to do is: I have a html file with javascipt embeded in, in this file I want to use a table object in another javascript file. How do I access this object? Your help is very much appreciated. Regards, lep2 I have two servers jboss and ejabbered and i have deployed two html files, one on each as follows: testdirver.html deployed on ejabbered <html><head> <script> function viewmembers() {var w=window.open("http://192.168.56.134:8080/nkms1/kms/test.html");} </script> </head> <body><form name="sub" > <input type="text" id="to" name="to"> <button onClick= "viewmembers();"> </form></body></html> test.html on jboss <html> <script> function abc() {alert(window.opener.document.forms[0].to);} </script> <body onload=abc();></body></html> Problem: window.opener.document gives the js error "Access is Denied" which i am not able to understand. Exchanging the two files on the servers(i.e. testdriver.html on jboss and test.html on ejabbered works fine and i get the output [object]). So i am guessing there is something that has to do with the ejabbered server This is a question more about an ASP.NET web application, but javascript is involved, so I'm hoping some javascript gurus can assist me. I'm working with a web application that needs to get access to an ASP.NET web control (a button) in javascript. The problen is that since the control is run on the server, javascript can't access it in the standard way (i.e. document.getElementById(controlId); ). I've actually solved this problem before in a different application, but my solution there doesn't seem to work here for some reason. I have this in an aspx file: Code: <script...> ... function myfun() { var b = document.getElementById("<%=SaveButton.ClientID%>"); alert(b); } </script> ... <asp:Button ID="SaveButton" Text="save" OnClientClick="myfun()" ClientIDMode="Static" runat="server" UseSubmitBehavior="False" /> I have a designer class in which the button is declared (and therefore exists in the server-side codebehind): Code: protected global::System.Web.UI.WebControls.Button SaveButton; But when I click on my button, the alert box says "null". Why am I not able to get my button in the javascript function? Some things to note: *The button exists within a content tag: Code: <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"> *I'm working within Visual Studios 2008. Hi All, I have html pages with code like <div> <script type="text/javascript" src="http://myserver2/mysite/addhtm.js"></script> </div> the script adds some html code and random images selected from second server inside an iframe tag in the div tag. I need to examine this added html and image properties in my page using javascript. A search on internet did not help, it says elements inside iframe coming from different domain can not be accessed. Is there any workaround or hack available to access iframe contents from page javascript? Thanks Here is the scenario friends, I have an html page which I load it on a server. I give the URL of this page to my clients. My clients have their digital certificate in their web browsers. There is some data on the html page which is filled by the clients. When the client hits the submit button, a java script should run from behind which should be able to pick up the digital certificate of the client which is laoded on their web browser. This information must be sent along with the data to the server. Is it possible to do this using Java script? Can we access Certificates on a system via Java script? Are there any API calls which can be used in Java script for this purpose? Any help will be appreciated. Thank you for your time. Regards, Rocky I am starting a new project soon. Now, the project is still in the stage of planning. But I am quite confuse now which programming language to implement. I am going to design a system where the normal users will update the data with the system while the data required changes will need system administrator to apporve it. I will need a database to keep those records (the data required update) so that the system admin can refer to the database and make changes. Do I have another choice instead of using Microsoft Access 2007 macros or VBA ? I prefer a web-based programming. Any suggestion, please ? Hi, Is is possible to access a global variable for use inside a function? Thanks for help in advance Mike ;(function($){ $.fn.superfish = function(op){ In the above code snippet: Firstly I find it odd the the line begins with a ';'. Is there a meaning to this? Secondly, what is the meaning of the '$' in this context and why does it appear that there is a parenthesis missing? I am good with C# and now I am learning JavaScript Thanks for the help out, joecamel Hi guys, I created a firefox extension a while ago & have just realised that the right click menu's don't seem to appear anymore... Have the methods I'm using been deprecated? Could someone point me in the right direction? Here's my old code.... Code: // This is our javascript, which will check the selected link or hyperlink function myfunction() { if (gContextMenu.isTextSelected) { var focusedWindow = document.commandDispatcher.focusedWindow; if (focusedWindow == window) focusedWindow = getBrowser().contentWindow; var url = focusedWindow.getSelection().toString(); var mySplitResult = url.split("\n"); for(i = 0; i < mySplitResult.length; i++){ window.open('http://mysite.com/mypage.php?url=' + mySplitResult[i], 'window name') } } else { try {url = gContextMenu.linkURL} // new FF, other? catch(e) { try {url = gContextMenu.linkURL()} // old FF, SM, other? catch(e) {url = String(gContextMenu.link)} // either FF, other? } window.open('http://mysite.com/mypage.php?url=' + url, 'windowname2') } } Many thanks in return! Hi, I'm having troube closing the main Internet Explorer window using a script called from a right click menu. The code I'm using is: Code: <script language="JavaScript"> var oWindow = window.external.menuArguments; oWindow.close(); </script> When the script calls, windows prompts to close the window, but when 'yes' is clicked the Alert sound sounds and the window remains open! If the script is called from a button on the page it will close, but I want to close any page on the internet using a right click! All help will be gratefully received. Dave. Ok, so the code below will open a DIV under the iframe when right-clicking inside the iframe. The DIV will display the mouse coords where it was clicked. This works in IE, but I can't get it to work in Mozilla (FF, Saf, Op, Chr). Any help appreciated! Code: <html> <body> <script language="JavaScript"> function initialise() { if (navigator.appName == "Microsoft Internet Explorer") { editorContent.document.designMode='on'; editorContent.document.attachEvent("oncontextmenu", showContextMenu); editorContent.document.attachEvent("onclick", hideContextMenu); } else { document.getElementById("editorContent").contentDocument.designMode='on'; editorContent.document.addEventListener("contextmenu", showContextMenu, true); editorContent.document.addEventListener("click", hideContextMenu, true); } } function showContextMenu() { if (navigator.appName == "Microsoft Internet Explorer") { var editorContentWin = document.getElementById('editorContent').contentWindow; var mousex = editorContentWin.event.clientX; var mousey = window.screenTop + editorContentWin.event.clientY; } else { /***************************************/ /* WHAT TO DO HERE TO WORK IN MOZILLA? */ /***************************************/ } document.getElementById("contextMenu").style.visibility = 'visible'; document.getElementById("contextMenu").style.display = ''; document.getElementById("contextMenu").innerHTML = 'X: '+mousex+' Y: '+mousey; if (navigator.appName != "Microsoft Internet Explorer") { document.stopPropagation(); document.preventDefault(); } return false; } function hideContextMenu() { document.getElementById("contextMenu").style.visibility = 'hidden'; document.getElementById("contextMenu").style.display = 'none'; } </script> <iframe id="editorContent" name="editorContent" width="400" height="400" frameborder="1" onLoad="initialise();"></iframe> <div id="contextMenu" style="width: 100px; height: 20px; border: 1px solid black; background-color: yellow; visibility: hidden; display: none"></div> </body> </html> |