Getting unload to work with a button cross-browser's - javascript

I am wondering if I can have the unload method in Javascript do a button.click; or a document.getElementById('target').click();
The reason for this is I want to clear the information in the browser but I can't seem to get the unload method to work right. But I don't even know if the unload method is capable of doing a button.click or a document.getElementById('target').click(); Is there like a list of things this method can or cannot do? here is the code I am trying to get working.
window.onunload=leave;
function leave() {
//alert("Leaving");
document.getElementById('kioskform:broswerCloseSubmit').click();
}
The alert seems to be showing in everything ("IE, FireFox,Safari") but in Chrome ('don't know why) but i can't seem to get the clear options i am using to work with the unload method. Not to mention I am wondering if there is a good way to detect which browser the individual is using to load in different parts of the unload script any idea's or suggestions or advice is greatly appreciated.

If you were to use jQuery , you could use the DirtyForm plugin. This would accomplish what you are trying to do.

Related

javascript - Simulate keyboard input in browser (noticable by React)

I'm trying to make a js macro which will fill 3 inputs needed for login. I need to make this a lot of times in a day, so this would help a lot.
The problem is that something so simple like:
input_name.value = 'somevalue'
won't work, because the page I'm login into is using React.
I think I need to simulate pressing a keyboard key somehow.
Is it possible? I tried a lot of methods, but none worked.
I also tried few Chrome plugins for this (like iMacros), but all of them doesnt 'trigger' React's mechanism.
Anyone have some solution?
iMacros should be able to simulate keypress using firefox/chrome plugins. iMacros EVENT Documentation
If that doesn't work you could use a hardware solution such as a Teensy which can act as a keyboard/mouse

How to find a form element inside multiple frames using jquery

I am working on a website that currently uses the old style frames. I want to go through a replace some javascript DOM calls because I am running into cross-browser issues. This is what I would like to replace.
window.parent.frames['topdisplay'].document.FORMSV2DISPLAY.action = 'what ever action';
In the above code my problem is that the 'document.FORMSV2DISPLAY' part doesn't work in IE I have to replace that part with document.form(0) and then of course neither of those work correctly in Chrome or Safari.
I would like to use jquery to find the form named FORMSV2DISPLAY and then perform my usual actions and submits.
I have tried things like
$(this).find('FORMSV2DISPLAY').action
$(parent).find('FORMSV2DISPLAY').action
$('topdisplay').find('FORMSV2DISPLAY').action
none of these return the same thing as the javascript DOM calls I am trying to replace. I am very new to jquery and help or understanding is greatly appreciated.
to set the action:
$('#topdisplay').find('#FORMSV2DISPLAY').attr('action', 'whateveraction');

Using data return from sharepoint assetimagepicker

I'm working with Sharepoint 2007. I use the built in AssetImagePicker.aspx and I need to retrieve the image url from that page and use it in my custom webpart.
I want to run my javascript code to run when clicking the OK button of the AssetImagePicker.aspx but I can't find a way to do that.
Does anyone know how to do this?
Thanks
Not sure if I'm understanding the question properly, and I know nothing about Sharepoint (and AssetImagePicker.aspx) but it sounds like you want to add an event handler to the OK button: to run a function when the click event of the button is fired.
You can either code event handling yourself (see W3Schools or Quirksmode for examples of this) or (probably better) use a library like jQuery.

JQuery simplemodal close on codebehind function

Here's the thing
I have this master page, and in one of its slave pages there's a couple of Excel report generators, which, when retrieving the data, they take quite an awefull time because of the ammount of the data.
Well, i'm using a simplemodal windows to show a little gif to keep the user entertained. The thing is, i want this modal to close once its done doing the work
I can close it with the ESC key, but i want it to close by itself once its done working. I already tried with this code
SimpleModal breaks ASP.Net Postbacks
but it didnt worked, maybe its cuz i'm creating an excel file from a gridview, and its writting the scripr to another buffer.
I'm thinking on having close button on the modal once the whole thing its finished, but i'd rather have it close by itself
Any idea on how i can accomplish this will be pretty much appreciated
While I can't provide much help with SimpleModal, maybe you shouldn't use a modal dialog to show a loading/progress icon. I would suggest taking a look at spin.js:
http://fgnass.github.com/spin.js/
This probably makes a little more sense for your use case, and is pretty easy to use.
Good luck!
Try appending to the .NET form, this fixes some issues with jQuery's dialog so it may help.
$("#sample").modal({
opacity:80,
overlayCss: {backgroundColor:"#fff"}
}).parent().appendTo("form");
On the "work is done", you can programatically close the dialog using:
$.modal.close();
Well, i didnt wanted to use a popup windows, but given that to create a Excel file from a gridview needs to write the html of the gridview on the buffer and execute it, it was never reaching the part where the javascript was to be written and executed, so, no other choise than send the dataSet over a Session variable into a popup windows which generate the excel file, so having somehting like a parallel work
I had a pretty ugly issue with IE8, my save dialog wasn't appearing, it worked on IE6 and IE7, as well with opera, firefox and chrome, but IE was giving a issue. Found there's a security option which that didnt allowed the save dialog to appear. For any one having a similar issue, its on Internet option -> Security -> Custom Level... -> Downloas -> Automatic Prompting for file downloads -> Need to be "Enabled"
Any way, thanks for tha help, hope this info also helps someone else!

How do I abort print?

Is there a way to abort the print event after a user has pressed the web browsers print button?
This works for print buttons within the HTML (jQuery):
print_btn.click(function() {
if (confirm("Are you sure you want to print? Consider the environment")) {
window.print();
}
});
Is there a way to do the same with the web browsers print button? For IE there seemes to be a onbeforeprint event, but from there I can't find a way to abort the printing.
Thanks!
This isn't possible in general, and honestly I'm quite glad that's the case.
You could, however, do something dirty like make a style sheet that uses media selectors to make everything display: none; when printing, or something similar. I haven't ever tried this but it seems totally within spec (if completely pretentious).
Have you tried to return false; in IE's onbeforeprint event?
I doubt it's possible in any other browsers but IE. Having said that, it wouldn't surprise me if it worked in IE using the onbeforeprint event. Shocking, I know.

Categories