clonetrooper9494 Posted October 27, 2007 Share Posted October 27, 2007 I need a script that can let the person choose if they want to leave... I am working on an HTML lab but when you refresh, the HTML in a box gets deleted... but if I could prevent them form leaving, my problem would be solved.... but I can't find a script that will do that... (P.S. I have already tried to have it copy it to their clip board but my site won't do that... ) any ideas?So far... I have this, but if you press cancel, the page still reloads! <script type="text/javascript">function goodbye() { var leave=confirm("Are you sure you want to leave?") if (leave==true) { return true } else { return false } }</script></head><body onunload="goodbye()"> Oh, and if isn't possible, please tell me so I can stop checking back here! Link to comment Share on other sites More sharing options...
Jesdisciple Posted October 27, 2007 Share Posted October 27, 2007 Get the value of the text area, store it with the server (AJAX), and put it back after the reload. (I doubt that the reload can be avoided.)EDIT: I think I edited this post between CloneTrooper's below 2, adding "store it with the server (AJAX)". Link to comment Share on other sites More sharing options...
clonetrooper9494 Posted October 27, 2007 Author Share Posted October 27, 2007 But that deasn't work, because as soon as they reload, the textbox resets. Copying just doesn't work (I have tried 4 different times to find a script that works) so there is no possible way to save or keep any of the data on the page.... click on my signature Link to comment Share on other sites More sharing options...
clonetrooper9494 Posted October 28, 2007 Author Share Posted October 28, 2007 I will try something like that Link to comment Share on other sites More sharing options...
Jesdisciple Posted October 28, 2007 Share Posted October 28, 2007 You could also store it in a cookie, which doesn't require AJAX or server space. Link to comment Share on other sites More sharing options...
clonetrooper9494 Posted October 28, 2007 Author Share Posted October 28, 2007 the site I am on is a 'freehostplace.com/mypage/index.html', isn't there a limit to how many dif cookies a site can have?I have another Q... I have an idea...make a pop up, window.openthere is a way to control the text that goes in to it... so I make it pop up with the text on the close! but how do you do that?here is what I have so far: <html><head> <title>JavaScript Popup Example 3</title></head><script language="JavaScript1.2">function poponload(){window.open ("", "mywindow");}</SCRIPT><body onload="java script: poponload()"></body></html> do I do document.write or something? Link to comment Share on other sites More sharing options...
Jesdisciple Posted October 28, 2007 Share Posted October 28, 2007 I've never heard of a limit on cookies, but then I don't have a site.I would recommend the AJAX solution over the popup; you control a popup by manipulating its JavaScript variable, which you won't have on reload. Link to comment Share on other sites More sharing options...
Synook Posted October 28, 2007 Share Posted October 28, 2007 I've never heard of a limit on cookies, but then I don't have a site.The limit is 20 cookies / site. Link to comment Share on other sites More sharing options...
Reg Edit Posted October 28, 2007 Share Posted October 28, 2007 I need a script that can let the person choose if they want to leave [... ]There is a body.onBeforeUnload event you could try. I haven't used it myself, but it says it does what you describe, with its own dialog box. I don't know how wide the browser support is for it, but apparently it can be made to work in at least IE and FF: see google results on this for more info. Link to comment Share on other sites More sharing options...
clonetrooper9494 Posted October 28, 2007 Author Share Posted October 28, 2007 I am reading the AJAX tutorial on W3Schools, but what area would I find how to make a pop up by manipulating JavaScript?I could try google...ADDED:I am 100% confused by AJAX! hmm... I am not sure what to do about this... the site I put my stuff on has a preview HTML button. I copied the text from the source of the page but it didn't work when I put in my webpage. the site must have a protection thing so you can't steal stuff. but any ways I am not sure what to do about this. I could try to find the code (I have seen at someother places) well, thanks every one for your help! Link to comment Share on other sites More sharing options...
Jesdisciple Posted October 28, 2007 Share Posted October 28, 2007 what area would I find how to make a pop up by manipulating JavaScript?Go to the bottom of http://w3schools.com/js/js_examples_3.asp (JS DOM Examples, under Examples/Quizzes, on the sidebar), under Window Object, and find these two links:Open a new window when clicking on a buttonOpen a new window and control its appearance(I'm giving directions rather than links so you'll see the page; it's a really good reference.)After reading your last paragraph, I'm confused, too.I copied the text from the source of the page but it didn't work when I put in my webpage.Why were you copying HTML from the page's source code to the page?but any ways I am not sure what to do about this.You're not going to try AJAX...well, thanks every one for your help!...and you're leaving this thread? We can probably help you with the AJAX if you'll tell us what confuses you.By the way, see http://www.nczonline.net/archive/2006/3/312 for the FF/IE onBeforeUnload event that Reg Edit mentioned. Link to comment Share on other sites More sharing options...
clonetrooper9494 Posted October 29, 2007 Author Share Posted October 29, 2007 Well, I guess I should still stay here... ok... the funtions are great and all but thats only what the URL is... but perhaps I could find a script that says if the URL ends in "/wait?yourtext=<center>hi</center>" paste it in a text box on that page. And before on that other paragraph, I meant on another page, it had a link that opened a page but there was no URL... it just said about:blank with a whole bunch of text and HTML displayed. if I could add a document.write thing for the pop up that would be great, or make the page the pop up goes to but I am not sure how to transfer info across the pages (except for the URL idea)! I will get back to you when or if I need help with AJAX. I will check back every day to see your posts. *goes off to find a script to read the end of a URL* Link to comment Share on other sites More sharing options...
Jesdisciple Posted October 30, 2007 Share Posted October 30, 2007 I believe the document.write for a popup is just: var win = window.open(url); //and any other argumentswin.document.write('Hi!'); For the parameters in the URL, you could use PHP's $_GET array or this: window.GET = function(){ var url = window.location.href; var array = url.indexOf('#') == -1 ? url.substring(url.indexOf('?') + 1).split(/&;/): url.substring(url.indexOf('?') + 1, url.indexOf('#')).split(/&;/); //URLs can be like either "sample.html?test1=hi&test2=bye" or //"sample.html?test1=hi;test2=bye" window._GET = {}; for(var i = 0; i < array.length; i++){ var assign = array[i].indexOf('='); if(assign == -1){ _GET[array[i]] = true;//if no value, treat as boolean }else{ _GET[array[i].substring(0, assign)] = array[i].substring(assign + 1); } }} Just call GET() at the beginning and retrieve variables like this: alert(_GET['test1']); or this: alert(_GET.test1); Link to comment Share on other sites More sharing options...
Nim199 Posted October 30, 2007 Share Posted October 30, 2007 <script type="text/javascript">function goodbye() { var exit=0 var leave=confirm("Are you sure you want to leave?") if (leave==true) { exit=1 return true } if (exit==0) { return false }}</script></head><body onunload="goodbye()"> This might sort you 'Cancel' problem. Link to comment Share on other sites More sharing options...
Jesdisciple Posted October 30, 2007 Share Posted October 30, 2007 Fermat, that behaves identically to the original. (I don't know what browser the OP was using, but Firefox completely ignores the return false and closes the window anyway.) Link to comment Share on other sites More sharing options...
clonetrooper9494 Posted October 31, 2007 Author Share Posted October 31, 2007 I believe the document.write for a popup is just: CODE: ...I tried that, but the window wouldn't open... (I was in a frame though...)And I was wondering where I would get the data in that one long code. I tried to make sence of it, but I don't konw that much about JS, what would I use to change the value of a text box to? Would I say document.textbox_I_want_text_in.value = "ARRAY" or any other vars in that place? How would I retrive the data if I were to put that in script tags? would I have to make it a function and then activate it?ADDED: I now see how to do the _get varibles stuff... and the new window thing works! but I would like to use the GET function for another page, but it doesn't work! (See post below) Link to comment Share on other sites More sharing options...
clonetrooper9494 Posted November 6, 2007 Author Share Posted November 6, 2007 I made a page here: http://free.hostultra.com/~clonetrooper/te...pie=dfgdfgshtrs, but for some reason, the alert isn't opening!here is the code: <html><head><script>window.GET = function(){ var url = window.location.href; var array = url.indexOf('#') == -1 ? url.substring(url.indexOf('http://free.hostultra.com/~clonetrooper/test123.html') + 1).split(/&;/): url.substring(url.indexOf('http://free.hostultra.com/~clonetrooper/test123.html') + 1, url.indexOf('#')).split(/&;/); //URLs can be like either "sample.html?test1=hi&test2=bye" or //"sample.html?test1=hi;test2=bye" window._GET = {}; for(var i = 0; i < array.length; i++){ var assign = array[i].indexOf('='); _GET[array[i].substring(0, assign)] = assign == -1 ? true ://if no value, treat as boolean array[i].substring(assign + 1); }}</script><script>function f2(){alert(_GET['test1']);}</script></head><body><img src="http://**************.com/images/*****.jpg" onclick="f2()"></body></html> Where did I go wrong with the code? Link to comment Share on other sites More sharing options...
justsomeguy Posted November 6, 2007 Share Posted November 6, 2007 Array is a reserved word, and an object name. Don't use array as a variable name. It also looks like you aren't running the window.GET function anywhere. And, your script tags need language attributes on them. Link to comment Share on other sites More sharing options...
clonetrooper9494 Posted November 7, 2007 Author Share Posted November 7, 2007 Another person gave me this script , *scrolls up*, and I have no idea how it works... Still reading the tutorials on the website. Is there any way to make the array a variable? How would I do that? (Never did understand array's... I am still reading the tutorial.)Plus, my body onunload script isn't working!(I just cut this out of the source, the tags are all there... http://free.hostultra.com/~clonetrooper/htmllab2-0.html) function boom(){var b4 = document.getElementById('T1').valuevar win = window.open(); //and any other argumentswin.document.write(b4 + '<br>here is your text...');}</script></head><body onunload="boom()"> I have all the pop-up-blockers off, I said onclick="boom()", and it worked then, so I changed it to onunload="boom()" and it stopped working after I refreshed it a couple times! I set the site as safe so the pop-up-blockers shut off, just the pop-up isn't poping-up! Link to comment Share on other sites More sharing options...
justsomeguy Posted November 7, 2007 Share Posted November 7, 2007 Is there any way to make the array a variable?Yeah, give it a name other then "array". You can't use reserved words as variable names. "Array" is a reserved word. Link to comment Share on other sites More sharing options...
clonetrooper9494 Posted November 7, 2007 Author Share Posted November 7, 2007 I am not sure if you saw it, but I have no clue how to deal with arrays... as in I didn't know any of that and don't know how to give it a new name... if that makes any sence. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.