Center prompt window of window.onbeforeunload - javascript-events

How do I center the prompt of the window.onbeforeunload event. What do I need to add on my script in order for the prompt to show in the middle of the screen.
window.onbeforeunload = function() {
return "";
};

I think, that is not customizable.
I mean what all you can change there is the prompt messsage of the prompt. Otherwise you can not change the UI of the prompt, and you can not perform any other action on choosing the options there...
Everything in there like popup UI, button names will be changed according to browser.

Related

Why Cypress test is not able to trigger a script in a child window?

I have a pop up window containing a script in its head. And this script should be triggered by click on the window button. But after click on this button the script does not run. Could you suggest the reason?
Steps to reproduce:
Click on a button in the main window.
Child window containing a simple form is open.
Move to the child window, fill in the form fields and click on submit button.
Expected result: The click triggers a script located in the child window head. The script process the form and submit it.
Actual result: an error arises: "submitMyForm is not defined" (reference: submitMyForm() is a method containing in the script mentioned above).
So the problem is that the child window form fields can be populated and form button can be clicked but the script bounded to the button by means of the link <a href="javascript:submitMyForm();"> does not work as the function submitMyForm() is not found. Obviously the reason of the test failure is stubbing the child window which is performed to prevent having 2 windows at the same time. After this the child window is opening in the same browser tab as Cypress is not able to work with 2 windows open in the same time. But in this case the script stops working neither from the test nor by performing the click manually.
Here is a code snippet from the Cypress test:
const pop_url = `/dir1/dir2/file.php?id=${sectionId}`; // Here is a new window URL
cy.window().then( win => {
const stub = cy.stub(win, 'open').as('windowopen');
newSurveySectionListObj.AddNewBtnClick(); // Triggers form opening in the new window
cy.get('#windowopen').should('be.called.with', pop_url);
cy.window().then( $win => {
$win.location.href = pop_url
newSurveySectionListObj.typeDropdownSelect('Matrix'); // works fine
newSurveySectionListObj.modalDescriptionFldType('Cypress test string'); // works fine
newSurveySectionListObj.responseTypeDropdownSelect('Checkbox'); // works fine
cy.get('a[href="javascript:submitMyForm();"]').click(); // Does not work despite the button is clicked. An error "submitMyForm is // not defined" arises
});
});
You are going beyond what Cypress is capable of/designed for.
I would question why you are using a separate window in your app? You will run afoul of pop-up blockers that will prevent the new window being opened anyway. A percentage of users won't be able to work it out.
There are 2 approaches to this:
Use a modal dialog to achieve this (not great on mobile)
Use another route/page to display your form, return to the prev page when done
These have the advantage that they won't break with pop-up blockers, and your Cypress tests will work, as they are still in the same window.

Place cursor in edit control box in visual studio

I am trying to make a password dialog box in a visual studio software. As soon as my password dialog box opens, I want the cursor to be placed in the edit control box so I can type password on it.
How can I put or place cursor in a text edit box in visual studio MFC without a mouse click?
Please suggest me how to do this.
static CEdit *ptrCurrentEditWindow;
BOOL GET_PASSWORD::OnInitDialog()
{
CDialog::OnInitDialog();
SetDlgItemText(IDC_PASSWORD, L"");
ptrCurrentEditWindow = &m_wnd_password;
return TRUE;
}
The documentation for CDialog::OnInitDialog explains, how to do this. The return value section has this information:
Specifies whether the application has set the input focus to one of the controls in the dialog box. If OnInitDialog returns nonzero, Windows sets the input focus to the default location, the first control in the dialog box. The application can return 0 only if it has explicitly set the input focus to one of the controls in the dialog box.
That leaves you with 2 options:
Make your edit control the first control, and have Windows handle everything for you by returning TRUE.
Move input to your edit control manually (CDialog::GotoDlgCtrl), and return FALSE.
Addressing the updated question: The implementation already does, what you need, as long as you make IDC_PASSWORD the first control in your dialog template. If you do not want to or cannot arrange for this, you'll have to manually move input focus, like this:
BOOL GET_PASSWORD::OnInitDialog()
{
CDialog::OnInitDialog();
// Not needed; an edit control is initially empty
SetDlgItemText(IDC_PASSWORD, L"");
// Set input focus to the desired control
GotoDlgCtrl(GetDlgItem(IDC_PASSWORD));
// Let the framework know, that you already set input focus
return FALSE;
}

Appcelerator sidemenu redirect to another screen creating multiple screen

I am using this sidemenu module in my app.
In sidemenu i have option like home, setting etc.
When i click on setting, it redirect to setting page.
Now problem is when setting page is opened and i open side menu using swipe and again click on setting then it will again open setting screen on previous one.
Means it creating 2 setting screen.
If i repeat it again then it will creating again setting scree.
How do i prevent this?
My code for screen redirection is here
var win = Alloy.createController('Setting').getView();
window.closeOpenView();
$.navWindow.openWindow(win);
Store last opened page:
Add this outside the click function
var openWindow = '';
And this inside the click function
if (openWindow == 'Setting') return;
openWindow = 'Setting'
var win = Alloy.createController('Setting').getView();
window.closeOpenView();
$.navWindow.openWindow(win);
This assumes this is in a function, which I guess it is because it is a click handler. If not, wrap it in a function

Click text-link image opens up in a box

I want to write code for a pop up when you click a text link like: "Click here for my CV". Upon clicking, I'd like a pop up with my image in it, not to have it open in a new window.
I tried with Lightbox but it didn't work for me. The image popped up in a new window, which isn't what I want.
How can I do this?
As far as I can see, you will need to prevent the default action caused by clicking the link.
here is a fiddle to help
https://jsfiddle.net/bsasi/xu58hb67/1/
$("a").click(function(evt){
evt.stopPropagation();
evt.preventDefault();
$(".lightUp").toggle();
});

is there a way to open a popup box in the center of the screen when somebody click the close button on browser?

i want to show a % discount box on the center of the browser when somebody clicks the close button of the browser window . I have tried the
window.onbeforeunload = function (e) {
};
function formSubmit() {
window.unbeforeunload = null;
}
function but it opens the browsers own dialogue box, how can i customize it? or better, how can i open my own box? so that i can change the position and style of it.
Any help will be greatly appreciated,
Thank you,
The onbeforeunload event is the only event that fires (besides the onunload event, but don't use this) before the window leaves the page. The onbeforeunload event is special because it is the only event that will automatically be fired off once the user tries to leave the page, but has the option of staying on the page if the user clicks cancel.
So, to directly answer your question, if the user closes the window, hits the back button, or navigates to a new URL, you will have to use the onbeforeunload event. You can add text inside of the pop-up, but some of the default text will always stay there. You just have to return a string.
Now, if the user were to click on a link that is a part of your application or tries to log out, you can anchor an event to that, which could make a window pop up that has the "% discount box". The reason you can't anchor an event to the back button, external URL, or the close window button is that they don't belong to your application. So once they click one of those, the browser goes off on its way with nothing you can do, except for the onbeforeunload event.

Resources