Javascript Back Button in Modal - Stop it from closing the modal - javascript

How do I get the "back" button seen in my demo to NOT close the modal window?
If this can't be prevented, then at least provide them with a confirmation box alerting them the window is trying to close and ask them if they want to continue.
I'm using a javascript back button link and forward button link to control the user's history inside a modal/lightbox window.
Here's a demo of what is happening... When you begin, the second page will have a link to the modal window, so click that, then click the "back" button in the window as it will take you BACK to the start page. That's the issue I'm having as I don't want this to happen.
http://www.apus.edu/_test/evan/modal/start.htm
Back Button
Foward Button

If you can see where they are in the page (ie: the start page having a static back / forward button ) why not just make the back button a javascript:void(0)? If you aren't going to have a defined front location, use server side to store their start place, and once they have reached it, disable the back option.

Related

How to bring popup browser window to the front so its on top of all browser windows?

My application gives users a specific amount of time to pay for a service. We do this because we can only keep their reservation for X amount of time.
The time we give them should be sufficient, however if they are running out of time we notify them with a Bootstrap Modal as shown below:
However, as soon as the modal achieves focus by the user clicking on the button or anywhere on the modal window, the PayPal browser window moves behind the main window. See picture below.
Simple clicking anywhere on the black overlay will bring the Paypal browser window back. However, I was hoping that someone might have some idea on how to achieve this using the button click in the modal.
In other words, how can I bring the Paypal browser window back to the front by clicking on the 'Yes Please' button on the modal or the close event of the modal?
I have tried to simulate the clicking of the overlay element in code but it does not seem to work.
Here is the code of the page:
From what I have read because the PopUp browser window is being opened from an iframe and the content is from a different source I cannot access the popup for security reasons. So there is no way to move it to the front unless the user clicks the dark overlay or the link 'Click to Continue'

How to focus on the trigger element which opens and modal and once the content is saved the whole page destroyed and rendered again

This is more of an architectural question, so in a webpage I have a edit button when allows me to edit a record. As soon as I press the edit button a modal opens up I change some of the records info and I hit save.
The focus returns to the (X) close button of the toast(save confirmation) for a second and even before the toast disappears focus returns to the browser since the save refreshes the page and the dom is destroyed and created again.
What we expect to do is once we hit the save button in the modal, focus should go to the toast (x) close button and wait till the confirmation dialog(toast) disappears and then return to the edit button again.
So there is 2 problems to be solved
How to set focus on the edit button(trigger) when the dom is destroyed and created again once we hit save button in the modal, coz there are a few buttons before that like new, view and then edit. how to specifically set focus on the trigger element?
How to create focus stack where we can specify that the focus should go to toast first and the n to the trigger even if the dom is destroyed and created again (is that possible)?
When I say "the dom is destroyed and created again" is it about replacing DOM content partially? Or the whole page is reloaded?
Just the header panel in which these trigger buttons (New, Edit, View) are destroyed and created again. So only partially the dom is destroyed and created again
A toast message is typically temporary and goes away on its own. It should be unobtrusive so that it can be easily ignored. If you have an X close button and you want to user to click on it (or hit ESC) to dismiss the toast message, then you really have a modal dialog instead of a toast message.
On sites that I've used that allow editing and saving, I've found that just a simple save message right on the page is sufficient. The save message can be an aria-live region so that the message is read for screen reader users. The save message usually goes away if I start editing other fields.
If you have to force focus to go back somewhere after a DOM is recreated, you'll have to save where you were (cookie) and then get the save point and just call the focus() method on it.

Click button and after refresh click button from new page

Im trying to make a script for a game. Where I have to make just 2 clicks, but they are on different pages.
On page 1 I click on "Send"
javascript:document.getElementById('send').click();
When i click on that button, my page redirect to a "confirm" page. Where i need to click "Ok" button.
How can i do to click my first button and after redirect "auto click" the "Ok" button from the new page?
If you also own the second page, you can have the window.onload method check against the url, for example look for the query string ?clickthrough=true (which your first page redirects to) and if it exists simulate a click of the button.
E.g., first page redirects to /second?clickthrough=true, and your javascript on the second page checks the url like this:
if (window.location.href.split("?").slice(-1)[0] == "clickthrough=true")
// click the button
If you do not own the second page, then I'd hope there is no way to do this as it would suddenly open users to a whole host of vulnerabilities.

Browser window close and tab close

I want to create a JS function that detect only browser close and tab close functionality.
I used this code from http://ykyuen.wordpress.com/2011/02/22/jquery-javascript-capture-the-browser-or-tab-closed-event/
I works for me but when i place a cursor on address and hit enter it goes to kill page method. I need only to show alert when tab or browser is closed.
I am afraid this is not possible.
You cannot really make a distinction. When the user navigates away from your page in any way, you get the same events (beforeunload, unload). You can do some tricks (like in the link posted) whether the user clicked any of the links on your page or submitted one of your forms, but you cannot really differentiate between the refresh button, back button, the user entering a new address, the user clicking a bookmark, close tab, close browser, etc.

Prevent browser's back button from reopening pop up window on previous page

How would I prevent the browser from opening the pop up window that was displayed from the previous page when the user clicks the back button?
I hope that made sense but I'll explain it in point form below:
There are three pages: Page1, Page2, Page3
User loads Page1 and clicks a link to load Page2 in a new window using JavaScript (i.e. window.open(...)). The User can close Page2 anytime they wish-- but we'll assume the user does so before step 2.
User now clicks a link on Page1 to load Page3.
User is now on Page3 and clicks the back button on their browser.
Page1 is displayed in the browser but Page2 is displayed again in a pop up window.
So, I'm wondering if there is a way to prevent Page2 from popping up again. I am using classic ASP as well, if it matters.
If Page2 is opened as a result of clicking a link, how is it automatically being opened when the back button is clicked? Unless Page2 is opened automatically on the initial load of Page1, it shouldn't pop up due to the back button being pressed - pressing "Back" doesn't click a link on the previous page. I suspect something else is going on in your page - can we see some code please?
you can try creating a session variable on page2. and check if it exist upon opening of page1. or use a cookie.
EDIT:
Function IsPostBack()
IsPostBack = (Request.ServerVariables("REQUEST_METHOD") = "POST")
End Function
this will not detect a page refresh though..
The page was redirecting to itself and inserting the javascript code to pop up a new window based on the button pressed previously. I think it determined this via the post or get methods. I forget now.
As such, when the user presses the back button, they will reload the page with the embedded javascript code and not the original page.
We've since left classic ASP behind so I can't really test any suggestions but appreciate the help.

Categories