input type="file" auto click - javascript

How do I automatically open the browse dialog of an input type="file" when the page first opens?

I don't think you should do this. If you've ever visited a MySpace page, you know how frustrating it can be when a web page activates things on its own when the page loads.
Don't violate how the UI is supposed to work, let the user ask for the dialog.
Besides, if the users instinctively closes it like a popup, and then realizes they needed it, it may not be obvious how they should get the dialog back. Then they will reload the page just to show the dialog again -- all frustrating things you could be avoiding.
That being said, I'm not sure why you want to do this in the first place. This is just my first reaction to what you're asking.

This is completely impossible in Firefox.
In other browsers, you can:
document.getElementById('inputId').click();

fire the click event on the button on document ready
$(document).ready(function() {
$("#buttonid").click();
});

Related

How to make a postback when the user clicks the back button?

I have a webforms web app, and all I need to do is, when a user clicks on the browser back button, I want to make a post-back or reload my page so it makes the post-back itself so new data is loaded.
I am using a library called jQuery-backDetect
which allows me to detect browser's back button click and I try to do is to make a post-back using __doPostback('arg1', 'arg2'). But it won't work at all.
And the strangest thing here is that, if I have the browser's debugger (in developer tools) open, or I pause the code execution using a breakpoint, it works perfectly. Here is a simple code I have written:
$(window).load(function(){
$('body').backDetect(function(){
// Callback function
debugger;
__doPostback('arg1', 'arg2');
});
});
I have tried to go through all the question here but they didn't help.
As strange as the question sounds, I really hope someone can help me. Thanks
You might consider wrapping the page content in an UpdatePanel, that might help create the behavior you are looking for.

How to force alert window to pop-up

After several time showing alert window the browser ask whether to prevent creating additional dialog.
Is there a way to force JavaScript show alert window even the user has checked the 'Prevent this page from creating additional dialog' ?
No, there isn't.
Thank goodness.
(you could, however, fake it with a modal dialog--possibly jQuery UI would suit your needs)
The whole point of that checkbox is to prevent sites from continuously spamming the user with alert boxes, preventing them from accessing anything in their browser anymore, even switching tabs. If it were possible for a site to continue posting new alert messages after the user decided he doesn't want to see it anymore, the whole buisness of "Don't click this link" where you'd end up on an infinite loop of alerts if you did click it, would be made possible again. Nobody wants that.

Popup message when leaving page

I am looking to develop a small popup message which acts similar to the window.beforeunload function, to notify the user, that if they leave the current page, they will lose all of their data.
However the issue with the beforeunload event is it fires to often.
I would like to have the popup message fire only when a user closes the page, or clicks a link which takes them away from the current page, to ensure they are aware that their current action will result in the loss of the form data they have entered so far.
However beforeunload event goes further to fire when they refresh the page, which is not needed for this case, and also when the forum is submitted.
Could anyone advise me on the best way to develop this. I thought about using a basic confirm dialog and have it fire under the right circumstances, however is it possible to know if the user is refreshing the page, and if the forum is being submitted (without jQuery).
How can I have this dialog fire at the appropriate times?
Unfortunately, I don't think this is possible. The page unload events are very limited, for security reasons.
If you only want it to appear if the user added or changed formdata, why not check for changes in the data? If yes then return the question on beforeunload, if not do nothing.
Assuming that the form isn't too complicated, you could save form data by using Ajax call, which means there will not be a page reload. So, beforeunload will then behave as it was designed to.

popup loading window

I want a popup screen to show the user that "this part" or "that part" of my app is loading....A lot of things within my app is referenced content so sometimes it takes a sec to load...
I'm new to Ajax (so pardon me, please), but I want a popup window to appear to the user in Ajax or JavaScript to let the user know the app is "loading" when the user finger taps something that needs to load....For example content on the new screen....I hope I'm making sense here.... I don't know where to start when it comes to making this happen (cause I'm not a code warrior yet, still a bit green sry lol), so any help is appreciated. I'm using JavaScript and HTML5 so far, but I need a popup loading window widget...
You're probably looking for something along the lines of colorbox.js (http://www.jacklmoore.com/colorbox). In more general terms, what you're looking for is a modal dialog box. Modal dialog boxes can be contrasted with more basic dialog boxes that don't grey out the rest of the screen. jQuery UI includes such a dialog, which you can see here: http://jqueryui.com/demos/dialog/
Of course, these aren't going to give you a loading effect out of the box. You'll have to write code to check whatever loading conditions pertain to your app, then dismiss the dialog box. A very simple way to do this would be to use setTimeout in conjunction with an ajax call whose success handler dismisses the dialog box. Or, if you don't have a way to track your loading status, you could just use a simple dialog to prompt the user to wait (but that's not particularly nice for the user).

Javascript: detect when page has been navigated "back" to

Suppose I have a page open in a browser and I go to my address bar and enter another page. Then I hit the back button to go to my original page. I'd like to write some Javascript code that can detect this scenario and respond to it.
As best I can tell neither the ready event, the onload, nor any inline Javascript on the page itself is re-executed in this scenario. Is there anything else I can do?
Cross-browser support is important here. jQuery based solutions preferred but not required.
Edit for clarity: the navigation I'm assuming is Page A -> Page B -> back to page A where I'm assuming that Page B may or may not be under my control.
You should try to give the user a cookie on both pages, the navigated to page and the page itself, with dates and times and compare see if they're close, or if they show that he's been on one page, been on another, and then redirected.
Another option is to give the user a cookie when he is redirected
In Firefox, you can check for the DomContentLoaded event. For a cross-browser solution, a little more work is required:
http://dean.edwards.name/weblog/2005/09/busted/

Categories

Resources