HI I am working on rails application. I am using "window.onbeforeunload" property to detect unsaved changes in the page. Its working fine.
I am also using jquery-rails autocomplete gem to autocomplete text input just like Stackoverflow does. I want to use auto-complete option not to populate the text field but to let the user know that the value he is inserting in, is already added by some user and when user will click on that option user will be redirected to that page.
e.g consider scenario you are asking a question on on stack overflow. If you typed in something and you click on any other link on page it warns you about unsaved changes. I am doing the same. Now when stack overflow will auto-complete my question I want to click on the one of the option suggested by it & wants to go that question directly. But "window.onbeforeunload" property warns me before redirecting to the desired page. I want to bypass the warn message for that particular scenario. How to do this?
Run this script when you don't want the warning...
$(window).off("beforeunload");
I've just had to do the same myself with a save button that submits a form.
Check out my aceppted answer here: user-unfriendly onbeforeunload / onunload I believe it will do what you want. Basically you can overwrite your onbeforeunload when the user clicks the auto-complete link. If onbeforeunload doesn't return anything, the warning message won't pop up.
Related
I have a site built with Asp.Net mvc where I show a list of products and automatically fill in the default purchasing amount for those products in each corresponding input field.
However when i navigate to a different product catalog using the anchor tag the 'Changes may not be saved' alert pops up presumably because of the default values entered in the input fields.
Now I have tried to disable this alert using the following in my shared layout page inside of a script tag:
window.onbeforeunload = null
window.beforeunload = null
I have also tried various answers from similar questions but nothing seems to help.
Does anyone know how I can get rid of this alert?
Thanks in advance.
You may have more success using this for jQuery:
$(window).off('beforeunload');
You can also read about some of the caveats and potential pitfalls of the beforeunload event here.
Update:
Just to clarify a point further from a comment #Jamiec left, the event should be triggered in your project somewhere, try searching for beforeunload to see where it originates.
Apparantly the alert was being called from a directive created by a colleague, by disabling this directive the alert no longer appears.
Thanks to Jamiec for notifying me.
Using Jquery Try below code.
$(window).off('beforeunload');
This is best option for changes that you made may not be saved popup.
If you use javascript then you can use below code,
window.onbeforeunload = function () {return null;};
Ask a question, and while editing the body of your question, click on some link on the page. StackOverflow's script knows that you are not finished yet, and warns you about loosing your unsaved data. However, it's confirmation box is not a jQuery plugin, or anything like that. It seems that its confirmation box is browser-specific box, something like JavaScript's confirm box. To prove it, simply check it in many browsers and you see different UI styles.
How they've done it? Which JavaScript command?
The onbeforeunload Javascript event is what you're looking for.
Trying setting a global flag to know when the page is "editing" and then use the onbeforeunload event
window.onbeforeunload = function(){ return globalEditingFlag ? 'You are editing': null }
Look at this :
http://www.w3schools.com/js/js_popup.asp
The section about the confirm box
I am working on a simple javascript program that searches for a wine review on one or several websites based on which sites the user is interested in.
My problem is that the window.open command only opens the first website chosen by the user and seems to be unable to open the others. Also, after scrolling through the urls of the sites listed, I get an error message saying: 405 - Method Not Allowed
You can check the program out at: http://www.divinocards.com/search_engine_4.htm
I have spent several hours trying to figure out why the program is stalling as it is. I have used the debugger and it seems that all values are being correctly assigned. It's is just that I am unable to open multiple windows. It doesn't seem to be an issue with pop-up blockers either as I temporarily disabled those.
Any help would be greatly appreciated.
Sincerely,
OB
Change the type attribute of input from submit to button (for input with name="Find" and, in fact, all inputs that you use through JavaScript exclusively, i.e. not doing a real submit to server).
More details - your form doesn't have an action attribute. Take a look here:
http://www.w3schools.com/tags/tag_input.asp
What happens in your current code when you click on "Find" button is that you are doing a submit to an unknown location. As per the standard:
http://www.w3.org/TR/html401/interact/forms.html
this attribute is required (look at section 17.3 The FORM element).
The details in the section also explain why it redirects to "nowhere":
action = uri [CT]
This attribute specifies a form processing agent. User agent behavior for a value other than an HTTP URI is undefined.
So, at the end it's up to a specific browser to decide what to do here (an implementation detail, not something you want to rely on).
If you just want to open a target window, you can remove your <form> tag , and add a click event to the find button.
Set <input> tag's type attribute to button can't prevent form submit by use press enter in the text field
You can also disable onsubmit event of the form.
like
document.forms[0].onsubmit = function(){return false;}
when I load the touch Facebook login page in the webview, I want that the email field to be set to a value and it can't be modified and to accomplish that I have inserted a JavaScript code in the webview disabling that element. All works fine until I want to click the login button because the page refreshes instead of submit the login info. I've noticed that if I don't disable the item, the login button works fine but I don't know why occurs that.
What can be the problem? I've thought another way to make it works: Whenever the user try to modify the email field ignore whatever he do, but I think this is a less proffesional way to fix that.
Regards.
You can use jQuery to bind to the keypress event for the field, then use event.which to scan for keyInput and discard all charcodes. Then the field is not disabled, it just wont accept input.
I've not be able to disable the element and send the info, so I've chosen the other way, not allow the user to input anything with the parameter readOnly instead disabled. It's easier than the Mech Software's answer, althougt thank you for your answer.
I am testing a JQuery Web application. I have a JQuery popup that I simply cannot get the submit button to fire in Watir. The same pattern is used thought the application.
I have verified the button exists and have tried click, fireEvent you name it and am out of methods to call.
Has anyone solved this?
Which do you want ?
A. Control cursor and click "submit"
or
B. Simula te click "submit"
A:need to use Autoit and control cursor and click ,but only for windows OS. B:execute the javascript that when clicking "submit".
If B case,there is two ways I used always.
1.execute that code in URL-bar.
ex.) #ie.link(:URL, 'javascript:<-CODE->;').click
or
Make like that module and use it by include in test case.
ex.) #ie.excute_script(<-CODE->)
module Watir
class IE
def execute_script(scriptCode)
WIN32OLE.codepage = WIN32OLE::CP_UTF8
window.execScript(scriptCode)
end
def window
WIN32OLE.codepage = WIN32OLE::CP_UTF8
ie.Document.parentWindow
end
end
Maybe...
I hope it help.
Sorry my poor english.
tknv/
In my case the solution was to use and index value of 1. JQuery creates a copy of the form and all the popup items have an index of 1. The 0 index controls are on the original form.
I just had the same problem. Ajax upload for jQuery demo is an example page. I want to upload a file using Upload button on the left hand side of the page.
When I click Upload button by hand, file upload pop up appears.
When I click the button with Watir, nothing happens.
Gary (accepted answer) helped me to find a solution:
browser.file_field(:index, 1).set "/path/to/file"