Clear UNDO history of events in browser with JavaScript? - javascript

I have a CodeMirror instance written in Javascript that acts as a code editor. I load the code for the procedure the user selects..when the user selects one procedure then another I just call the set the value to the code of that procedure. When I do this and the user clicks CTRL+Z or right click, undo it brings back the previous procedure. I need to clear the undo history when I call set value..can't find out how to do this have looked all over..any help?

What about clearHistory() . it works for me. call it when user selects a procedure.
editor.clearHistory()
or you can completely disable the undo feature by using "undoDepth" in codemirror configuration
undoDepth : 0 ,

Related

How to handle browser back button using javascript?

In my application, First I need to select an option and press next button.
Then I click on browser provided back button. That option should be selected when I come back to that page.
How can we do this with javascript?
You need to use Jquery/JS Session object to store your data. In your scenario whenever you select the option just update your storage object localStorage.setItem("optionVal", "test");
so when you go next and comeback to using back button just check if the optionVal is not null and has some value if it has some value just bind it with the drop down DOM. To check/get data you need to use localStorage.getItem("lastname"); since you have not provided I can just tell you the approach. Here are some links that might help:
http://www.w3schools.com/html/html5_webstorage.asp
You can create a Wizard for this process like payment option in e-commence site
http://bootsnipp.com/snippets/featured/form-wizard-and-validation
http://formvalidation.io/examples/bootstrap-wizard/
if you send the whole scenario then may me help with complete code

CRM 2015 Javascript, prevent record form from SAVE AND CLOSE

I need to develop a custom function using JavaScript for CRM 2015. What I would like to achieve is when a user hits 'Save and Close' button, it prevents record form from saving and close if the validation is not passed.
I googled it and tried eventObj.getEventArgs().preventDefault(); return false; which most people recommended. It does prevent form from saving, but the form still closed. The reason is that 'preventDefault canceled the save operation, but all remaining handlers for the event will still be executed'.
Is there a way to cancel remaining event handler, and prevent form from both SAVE and CLOSE?
If you have an web resource file, you can directly add button's command with Ribbon Workbench. Here is a link : http://ribbonworkbench.uservoice.com/knowledgebase/articles/80806-download-ribbon-workbench-for-crm-2011-2013-2015
For doing that, here is the steps :
1. Right click to "save & close" button and click customise command.
2. After that, you must see the created command for button in commands section.
3. Right clik the command and select edit actions.
4. Select add, then select "Javascript Function Action".
5. Select your library and function, and write your parameters if you need.
6. Last step is publishing.
One thing you have to be careful about is you can fire just one function.
This can be painful but if have something like this :
function baseFunction(){
//steps
anathoerFunction();
}
function anotherFunction(){
//steps
}
This will not work with ribbon workbench. You have to use it in one function.

Simulate click on DIV

I am developing a desktop application in Delphi XE4 using TChromium component to display Google Voice webpage.
I need to start a call programmatically and I can't find a way to trigger the javascript code behind the button (it is a DIV) "CONNECT":
TChromium allows to execute javascript code and I already managed to simulate the click on "CALL" button using a javascript code that simulates the Key Event using the character "c" which display the panel. This works because Google Voice has shortcuts and "c" is a valid shortcut to start a call. Also with javascript I can set the number in the input field. My main problem is that I don't know how to simulate a click on "CONNECT":
As you can see, there is no ID, no onClick and there is no shortcut to trigger the Connect button.
I can get a reference to this DIV using the following code:
document.getElementById(":87.mi").children[0].children[0].children[5].children[1].children[0].children[0].children[0].children[1];
But it is not possible to trigger anything appending .click(). I assume it is because click() will trigger onClick method that it is not defined. Is there any way to know what javascript code executes when someone clicks over this div?
If the focus is in the "Number to call" input, I can press "TAB" to navigate to "Phone to call with", then to "Remember to choice" and finally to "Connect" where I can press Enter key to make it work also. I tried to use the same code as in the beginning to simulate the CALL button but this time with TAB (keycode 9 instead of 67) and it does not work as the focus does not move.
I tried to do it programmatically with delphi also using mouse_event, keybd_event, PostKeyExHWND, PostKeyEx32 and PostMessage with no results as the focus does not move away from "Number to call"
The only option that works by now is to move the mouse with delphi using SetCursorPos and simulate a click on that button calculating the coordinates but this will be my last option to choose as I would prefer a javascript code to do it.
Any suggestions are welcome!
I suggest the next solution.
In a javascript file that have to be imported from the view, put the next code:
$(".goog-button-base-content").click(function(){
//CODE HERE
});
What you do here is that everytime that we pressed the div that has that class, you will start the logic inside "CODE HERE"
(Sorry for my bad english)
I hope be usefully. See you

Change element value on external website

I have such a problem - I want to change value of an element on some external website.
Namely: I have webcam http interface which is password protected and there is a page with motion detection checkbox and "Apply" button (form submit). I want to create simple program with some sort of delayed toggling of motion detection (so I can launch this program and have some time to leave the building before motion detection starts). So I want to change checkbox state and write this change to system. I tried something like this, but that doesn't work:
jQuery.get("http://admin:password#192.168.0.1:12345/motion-page.asp",
function(data){
$('input[name="checkbox1"]').prop('checked', false);
// and there "simulate" clicking on Apply button - submit the form -- don't know how ...
}
);
Can anybody help me with this, please?
I would backtrack from the page that shows when you submit the camera form. See if the form itself is submitting the "turn camera on" variable as GET or POST. If you already know this, then all you would have to do is access the same URL as the form from the camera (assuming it's HTTP accessible on a network like this) and submit that same set of variables.
If you don't want to open a browser to do this, you could write yourself a custom application that submits it for you, but either way you have to open something to make the submission, as a script has to wait [X] amount of time before making the request. The fastest way will be through a browser.
I am not sure you need jquery for this (I never use jquery hardly at all). What I would do on the scripting side, since merely accessing this script means you want to activate the timer most likely, would be to create a timer object in javascript, and then make a single function that either accesses the URL of the camera form submission with the GET string parameters (that's easiest if it's doable via GET, because you wont have to build a form), or, if it's POST, have the function build a form and submit the form via POST to the same URL.
Google how to create a timer in javascript, and google how to automatically submit a form. Doing the code for you would be a waste of my time if you can figure it out on your own. If not, come back and we'll see what we can do :)
Good luck.
Why not after hitting the submit button, or after checking the box, have javascript actually run a timer? Look into the timer functions in js or jquery if that's more your thing. Not sure if you need it written to disk or whatever... since you're not giving much info, but whatever data you're wanting recorded could be captured when the box is checked and can be submitted along with the form whenever the timer runs out.
Submitting a form in jquery is simple:
http://api.jquery.com/submit/
:)

Confirm dialog box on unload/exit UNLESS the back button is pressed?

I have some simple code to display a confirm dialog box when the user tries to leave my form:
window.onbeforeunload = askConfirm;
function askConfirm(){
return "Your answers will be lost.";
}
But this is a multi-page form and they frequently press back to change some values on a previous page.
But when they do this dialog box still comes up.
Is there a way around this?
The answer I would suggest unfortunately doesn't actually answer your question but is a solution of a kind. The only possible solution here, imv, is to make sure that a user clicking the back button doesn't actually create an issue by storing the form answers from all pages. In the case of PHP I would store them in a session ($_SESSION). You have to recognise that users use the back button more than any other UI element within a browser. If your form truly has to be across a number of pages then you need to make sure the data they have entered is persistent across all these pages. I would actually provide a navigation for this within your own interface. Provide a clear sequential process visually and allow instant navigation through this process where possible.
I don't see a way to specifically detect whether the user pressed "back" or any other browser button. This is outside the site's scope.
Only one solution comes to mind: Show the confirmation dialog only when a global flag has been set to "true".
if (ask_when_exiting == true)
return "Your answers will be lost.";
You would have to set the variable to true? in the onclick event of every link that you want the confirmation to pop up for. You should be able to mass apply this event to every link on your page using JQuery or another JS framework (Seomthing like $$('a').each()....).
However, this will disable the confirmation for reloading the page, or any other event that is not triggered using a control on the page like typing in another URL or closing the browser, as well.

Categories

Resources