I want to trigger click on save button, on the page that comes right after window.print();
Is it possible? if yes, then please help.
window.print() opens the Print dialog box.
Mine has no Save button anywhere on it, and there is no way to interact with something that doesn't exist at all.
That said, browsers do not provide any mechanism for JavaScript to interact with any part of the Print dialog box at all.
Related
So, what I have is a lot of pages like this, with GET parameters: benchmark.php?game_id=87
that display the information about the particular game (info is in a database) and also contains an Edit button.
The Edit button opens a new window using JS window.open("edit_game.php?game_id=87",...)
The Edit window contains a few textboxes to add/modify data and a Save button.
The desired behaviour here is that when I press the Save button on the edit_game.php page, not only that the information is saved in the DB (this works) but also the benchmark.php?game_id=87 page is maybe refreshed so that the information displayed is actual. I don't know how to do the 'submit on page x, page y is aware and refreshes'.
I assume I should use AJAX for this but I don't know where to start. What I tried is something like this
setInterval( function(){
$('#refresh_station').load('game_information.php');
}, 2000);
that every 2 seconds it refreshes the information present in benchmark.php?game_id=87 but I find this very inefficient since it refreshes the info even if no modifications happened.
Is this the only way to approach this situation?
Edit: I should mention that edit_game.php?game_id=87 is not supposed to close or anything after pressing Save. So I can't just use the submit form to redirect back to benchmark.php.
Yes you should use Ajax for it also add one field in Database table last_update, now when page edit_game.php?game_id=87 load it have last_update time, ajax check this last update on some interval time if ajax see there is any update page should be refreshed.
Running a loop that checks every few seconds whether the records have changed isn't the best solution in my opinion. There's a much easier way to trigger a page refresh when you submit a form in a popup window.
Using window.opener you can perform actions on the window that opened the popup that you're currently in. In your case:
<form onsubmit="window.opener.location.reload();">
Your form here.
<input type="submit" value="Save changes">
</form>
Or in jQuery:
$('form').submit(function() {
window.opener.location.reload();
});
https://jsfiddle.net/yqv1eh8w/1/
postMessage
can communicate with the child window. Link
window.addEventListener("message", function (event) {});
will let you listen to it from a child window.
This should be help you with what you want.
The entire thing communicates with the help of events and messages.
Also, you will need to run this locally (coz I opened popups to the same window)
IMO, the best approach is to use a popup form. If your web page is already using Bootstrap, you can add a modal popup easily with the edit form as it's content. When clicking on the edit button, instead of opening a new window, you can open this popup.
Then submit this form with ajax on click of the submit button and inside the Ajax success function, add javascript/jQuery to close the modal and refresh the page content.
Currently, I have a javascript alert, like so:
<script type="text/javascript">
alert('Hopefully you will not see this screen too long, because that would mean that it is taking a while to load my page.');
</script>
I just have filler text right now, but I was wondering how to make it so that the popup will stay open, but the user can still click around and navigate the page. Right now, while open, no clicks can be made on the page.
Unfortunately, that's how the browser works. Nothing else can be done while an alert is active. Overall, it's a better user experience to implement your own. Recommend you use an alert library... my favorite is http://t4t5.github.io/sweetalert/
JQuery and Bootstrap both offer equivalents also.
This is a bit of an odd question, but basically, I'm trying to display different pop-up menus to a user depending on how they click my browser action button (the icon to the right of the Omnibar). One way that I thought of doing this is by detecting whether the user is clicking it normally or holding shift as they click it. Is this possible?
If there is no way of doing this, I would appreciate any suggestions as to how to display different menus to the user with a single browser action button. I would rather not make the user select from two options in the actual pop-up window - a single button press would be preferable.
Thanks
Edit: I'm thinking the best way to do this may be to check for the Shift key being pressed using Javascript as soon as the pop-up window is displayed, then display a menu according to that. I'm going to try that and report back.
I've tried for 2 hours, but didn't find a solution, too.
I think it's not possible to capture the click event, which opened the popup.
I know there is a very similiar question (JavaScript: How to select "Cancel" by default in confirm box?) on this site, but I felt like I did not get a good answer out of that one as my premises are not the same.
Problem description: I am writing a web browser Javascript popup window that is supposed to take some information as input and the user can choose between "OK" to process the information and continue with whatever, or "Cancel" to close the window and go back to whatever. So far so good. The problem is that some users press "X" in the upper right corner of the popup to close the window (either by mistake or actually believing that the data is processed) and get a second dialog popup (you cannot change the text in this dialog) displaying "Are you sure you want to navigate away from this page?" - "Press OK to continue, or Cancel to stay on the current page" - OK/Cancel... Now, some of the users just press enter on their keyboard and oops, the popup is closed and all information is lost.
Question: Can you, or is there a workaround to set focus on "Cancel" instead of "OK" when it comes to the dialog of whether to close an Internet Explorer popup/tab or not?
Thank you in advance! =)
Unfortunately, I don't think it's possible to change focus on browser-generated dialog boxes.
As Deestan suggested, maybe you can create a faux popup using js and css, and do whatever you want in terms of styling it, and still have the user enter information, and have the information passed to your code.
From what i've heard/read, it's generally accepted that using alert() or popup() for anything other than debugging is frowned upon.
I have a simple logon page. When the user is validated, the window navigates to a new page. The javascript is window.open('http://www.google.com',"mytest",'toolbar=no'); My expectation is that when it navigates away from our logon page and opens the google site that the back button would be disabled. But it's not. Does anyone have any idea why?
It depends on your browser. Ultimately, all you can do with javascript's window.open() is tell the browser what you'd like it to do, but it's not obligated to do it. Browsers can and do ignore some directives based on user preferences.
I believe the option your looking for is 'location=no', as that hides the address bar and therefore the back button too. The toolbar is things like favorites/etc.
This is bad practice - what happens if the user has javascript disabled? If the browser prevents the js from removing the toolbar of the main window?
Instead, amend the logon page to detect whether the user is logged in before showing the login form. If logged in, show a message saying so instead of the form - that way, a user clicking back won't be a problem.
I find it very annoying when a website messes around with my browser window, and generally don't come back.
This is what worked for me. Instead of disabling the back key. I listen for on unload event. I then write the following in javascript:
window.onbeforeunload = function () { return "You should not press the back button while in this application. If you continue, your work will not be saved and you will need to log back in."}
Java Script pops a dialogue box with OK and Cancel options. If the user clicks cancel. The application stays right where they are. The script is embedded within the tags. For me this is the ideal solution. I found this at
http://www.hunlock.com/blogs/Mastering_The_Back_Button_With_Javascript