I am using SharePoint 2010 and I have managed to get a list to open within a modal dialog. I am now trying to get another list to open within the same modal dialog when you click a button. (Ideally, close the first dialog then open another)
Here is my modal dialog declaration:
function OpenDialog(url)
{
var dialogOptions = SP.UI.$create_DialogOptions();
dialogOptions.url = url // URL of the Page
dialogOptions.title = 'Dialog Window'
dialogOptions.allowMaximize= true
dialogOptions.width = 635; // Width of the Dialog
dialogOptions.height = 335; // Height of the Dialog
SP.UI.ModalDialog.showModalDialog(dialogOptions); // Open the Dialog
}
function DialogCallback(){
SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.cancel,'Cancelled');
}
So I have managed to close the dialog correctly, but I cant seem to get it to open a new one. Ive used www.google.co.uk as an example, I just need it to open in either the same dialog (replacing whats currently there) or close the current dialog and reopen a new one...
href="#" onclick="window.frameElement.cancelPopUp(); OpenDialog(url);
You forget to option : dialogReturnValueCallback in you Option object.
You can pass a function to this parameter. When to Modal is Closed (ok, cancel ...) this function will be executed.
Do somthing like this :
function OpenDialog(url)
{
var dialogOptions = SP.UI.$create_DialogOptions();
dialogOptions.url = url // URL of the Page
dialogOptions.title = 'Dialog Window'
dialogOptions.allowMaximize= true
dialogOptions.width = 635; // Width of the Dialog
dialogOptions.height = 335; // Height of the Dialog
dialogOptions.dialogReturnValueCallback = Function.createDelegate(null,DialogCallback )
SP.UI.ModalDialog.showModalDialog(dialogOptions); // Open the Dialog
}
function DialogCallback(result, target) {
if (result == SP.UI.DialogResult.OK) {
//Close the Modal with the function : SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.OK, returnValue);
//Here Your First Modal is close normaly, open Your New Modal Dialog
}else if (result == SP.UI.DialogResult.cancel){
//Close the modal with the function : SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.cancel,returnValue);
} else{
//The user have closed the modal with the cross
}
}
So in your Parent page, jsute call :
OpenDialog(url);
In your First Modal, to close normaly the Modal :
SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.OK, "a value to return ...");
And then the DialogCallback function will be executed, and then you can open you new Modal
Related
I am trying to get the reference of the newly opened tab and use it in the same function to close the tab and reopen,
for more details:
I want to create a Java script button
on the first click open a new tab
on the second click of the same button close the tab and reopen the same tab
var Window;
// Function that open the new Window
function windowOpen() {
Window = window.open( "https://www.google.com/", "_blank", "width=400, height=450");
// if (window.opener) {
// window.opener.announceWindow( window );
// }
}
// function announceWindow( win ) {
// window.close();
// }
<button onclick="windowOpen()" target=_blank>
Open Window
</button>
You could use something like this:
let google;
let open = false;
function toggleWindow() {
open = !open;
if (open) {
google = window.open("https://www.google.com/", "_blank", "width=400, height=450");
} else {
google.close();
}
}
You can do like this:
var Window = window.open('https://www.google.com');
function windowOpen() {
if(Window !== null){
alert("Window alreay open");
Window.close();
Window = null;
}else {
Window = window.open('https://www.google.com');
}
}
<button onclick="windowOpen()">
Open Window
</button>
open() function opens a new tab. It's name property has _blank value by default. But if you close the tab manually, then you have to refresh the page to work JS properly otherwise you will get alert "Window already open" even after the closing of the tab.
So i have a button on the footer of the website, that has the class ".subscrever" and that triggers a popup open on click.
http://salpoente.pt/
I can i make a custom URL to trigger that click? For example "http://salpoente.pt/#subscrever" . How do i make this custom URL trigger that button click to make the popup open? All i want is to have a custom link that i can use for the client to open the site and have the popup opened already.
Tried everything with jquery and didnt managed to do it.
You can use a URL parameter, such as http://salpoente.pt?subscrever=true.
Then, you have to get the parameter when the page loads:
function getParam(param)
{
var url= window.location.search.substring(1);
var urlParams = url.split('&');
for (var i = 0; i < urlParams.length; i++)
{
var paramName = urlParams[i].split('=');
if (paramName[0] == param)
{
return paramName[1];
}
}
}
$(document).ready(function() {
if(getParam("subscrever") === true) {
$("#subscrever").click()
//Or just call the button's onclick function directly
}
});
Don't think about it as the link clicking the button; the link opens the modal, and so does the button.
if ( window.location.hash === '#subscrever' ) openModal()
Below is the piece of code I am using to open a link in a new window say "abc".
If the user again clicks on the same link, it should close and reopen the link in the same window "abc".
window.openOrFocus = function(url, "abc") {
if (!window.popups) {
window.popups = {};}
if (window.popups["abc"]){
var v=window.open("", "abc");
v.close();}
window.popups["abc"] = window.open(url, "abc");
}
But Now, say I click on the link, it opens the URL in a new window named "abc".
Now I go and close the window "abc". and go back and again click on the link.
That time it shows up the pop up blocker.
I am confused as to why this pop up blocker is coming when the I go and manually close the window and try to reopen by clicking on the link.
Happens both in IE as well as Chrome
Probably because you're calling window.open with a blank URL or repeatedly in that case.
You don't need your window.open("", "abc") call; instead, just use the window reference you already have:
window.openOrFocus = function(url, windowName) {
if (!window.popups) {
window.popups = {};
}
if (window.popups[windowName]){
window.popups[windowName].close();
}
window.popups[windowName] = window.open(url, windowName);
};
I would also listen for the unload event so you can remove your reference:
window.openOrFocus = function(url, windowName) {
if (!window.popups) {
window.popups = {};
}
if (window.popups[windowName]){
window.popups[windowName].close();
}
window.popups[windowName] = window.open(url, windowName);
window.popups[windowName].onunload = function() {
delete window.popups[windowName];
};
};
Side note: This is a syntax error:
window.openOrFocus = function(url, "abc") {
// --------------------------------^
I've replaced it with windowName in the code above.
I need to differentiate between user driven close of a popup window using X close button and close through code.
var win= window.showModelessDialog("http://localhost/test/test.aspx",'google,....);
//Some manipulations
//Manipulation ends
if(win!=null && win.open)
{
win.close();
}
Now I have full access over test.aspx and test.aspx.cs.I have a onbeforeunload method defined in test.aspx page which will be called either way I close the window(X close or my code gets executed)I basically want to differentiate my X close and programmatic close so that I can do some backend manipulations
Something like this perhaps:
var MyPopup = {
_win : null,
_userClosingWindow : true,
open : function() {
var _this = this;
this._win = window.open(...);
this._win.onbeforeunload = function() {
if( _this._userClosingWindow ) {
// closed by user
}
else {
// closed in code
}
};
},
close : function() {
this._userClosingWindow = false;
this._win.close();
}
};
Then you can use MyPopup.open() and MyPopup.close() and still know when the close function is called or when the popup is closed by the user.
Use Model Popup & include "OK" & "Cancel" Button.
Now you can handle both the "OK" & "Cancel" Button Events.
you can use:
AjaxControlToolkit - ModalPopup
jQuery UI - Dialog
// parent
function closePopup(win) {
win.close();
// do the magic stuff...
}
// popup (test.aspx)
function closeMe() {
self.opener.closePopup(window);
}
Update
As of your comment, just check the closed property of the popup. If it is false, the popup is still open, otherwise it has already been closed
if (win.closed === false) {
win.close();
// do magic stuff here
}
I have a jsp file which calls another jsp file opening it as a showmodal dialog window.
Say file1.jsp calls file2.jsp through file1.js.
File1.jsp-->File1.js (respective js files)
File2.jsp-->File2.js(respective js files)
Now to handleonclose in File2.jsp I added a function in File2.js.
When I hit close window but choose option as cancel, instead of just showing the old window.
It shows a modal window ontop of the existing modal window. Why is this happening. Am I missing something obvious.
What i expect to happen: When I choose Close but click cancel, nothing should happen.
File2.js function:
function handleOnClose() {
var resultsDoc = document.frames('searchBuffer').document;
if (event.clientY < 0) {
var bool = confirm('Are you sure you want to close the window ?');
if (!bool) { //Issue occurs here
window.showModalDialog("File2.jsp", "", "dialogWidth:1000px;dialogHeight:650px");
}
else {
resultsDoc.all('searchResults').innerText = '';
document.someSearch.submit();
}
}
window.returnValue = 'Discard';
}
Modified File2.js function:
function handleOnClose() {
var resultsDoc = document.frames('searchBuffer').document;
if (event.clientY < 0) {
var bool = confirm('Are you sure you want to close the window ?');
if (!bool) { //Issue occurs here
//*******removed the showmodal dialog window call
window.returnValue = 'Sorry';
}
else {
resultsDoc.all('searchResults').innerText = '';
document.someSearch.submit();
window.returnValue = 'Discard';
}
}
}
On the calling js (file1.js) I check if return value is "Discard" if so I refresh the page.
Otherwise I call the showmodal window again. My result is stored in the buffer so retrieval isn't a problem. Works like a charm