Open another page in Dialog box - ms-office

I am trying to use Dialog box.
In my add-in, I have two buttons openGoogle and openStackoverflow which link to openDialog("https://www.google.com") and openDialog("https://www.stackoverlfow.com"):
function openDialog(url) {
Office.context.ui.displayDialogAsync(url, { height: 1100, width: 1000 },
function (result) {
console.log("here")
dialog = result.value;
}
)
}
First, I open one dialog by clicking on openGoogle, then if I click on openStackoverflow, here is displayed again, however the dialog does NOT go to stackoverflow.
Does anyone know what's wrong?

From the documentation:
the page, controller method, or other resource that is passed to the
displayDialogAsync method must be in the same domain as the host page.
If you need to get users to another domain, you can do this by first opening a dialog to a page within your add-in that then immediately redirects them to the external domain using window.location.href = "https://www.stackoverlfow.com";

Related

Send a message from host page to Dialog box

I am trying to use Dialog API of Office Add-ins.
According to the doc, we could use Office.context.ui.messageParent to send a message from the Dialog box to the host page (eg, task pane). Whereas, I don't see how we could send a message from the host page to the Dialog box.
Does anyone know how to do this?
There are 2 possible solutions:
Send data as query params, when you open a pagein dialog box.
If there are in same domain then localstorage should be available in dialog which was opened.
setInterval(function () { var value = localStorage.getItem("dataFromDialog"); }, 500)
You can write the same value in localStorage in dialog localStorageSetItem("dataFromDialog", "message to parent")
This feature is now in preview
See https://learn.microsoft.com/en-us/office/dev/add-ins/develop/parent-to-dialog
Example from the post:
Office.context.ui.addHandlerAsync(
Office.EventType.DialogParentMessageReceived,
onMessageFromParent);
function onMessageFromParent(event) {
var messageFromParent = JSON.parse(event.message);
}

Sharepoint 2013 Adding a add new event link in content editor

I would like to add a "Add New Event" link in a content editor web part to the calendar page. When clicked should open the default "new event" window to add an event. How can do that? what should be the link look like?
Thanks
Ganesh
If you want to open the form in the whole page, the link should be like this:
Add New Event
To open in a modal dialog:
function openDialog() {
var url = "<weburl>/Lists/<calendarlist>/NewForm.aspx";
var options = {
title: "Add New Event",
width: 400,
height: 600,
url: url
};
SP.UI.ModalDialog.showModalDialog(options);
}
Add New Event
Overwrite <weburl> with the web relative url and <calendarlist> with the relative url of the list (most of times the list name)
Example: https://mysiteurl/Lists/Calendar/NewForm.aspx
In a site page, click edit page and click on Add a Web Part.
Select your calendar list from Apps section in Categories.
Once your calendar is in your Site Page, click Add a Web Part again.
Select Content Editor Web part from Media and Contents section.
Inside Content Editor webpart click on "Click here to add new Contents"
From the ribbon, click on "Edit source".
[enter image description here][1]
Type or paste following code:
Add New Event
Lastly Click on Save page.

what is the use of window.open('','_self').close(); in chrome extension

When I click the extension icon, a popup is shown.
After that, when I try to click "URL restrictions", it will open a window, after that when I click the popup again, the popup is overlapping that url restriction window.
The above issue happens on Windows only, not on Linux.
So I have added window.open('','_self').close(); which apparently fixed the issue. But not exactly. Is it correct? I have referred this Link and Link2 but can not understand the meaning.
What is the purpose of window.open('','_self').close();?
EDIT: this is my popup.js
function click(e) {
var windowObj = window.open(site_exception_url, 'url_window', params);
windowObj.focus();
window.close();
window.open('','_self').close();
return false;
}
On Windows the popup isn't closed automatically after a new window is opened from a link within the popup.
Close it in the click handler manually, this won't hurt Linux but will help on Windows:
document.addEventListener("click", function(event) {
if (event.target.localName == "a") {
close();
}
});
The related questions linked in your question don't apply here as the first is for userscripts, not extensions, and the second isn't for popups shown by the browser when you click the toolbar button.

Tabs repeat on click page action

background.html:
// Called when the url of a tab changes.
function checkForValidUrl(tabId, changeInfo, tab) {
if(changeInfo.status === "loading") {
if (tab.url.indexOf('google.com') > -1) {
// ... show the page action.
chrome.pageAction.show(tabId);
chrome.pageAction.onClicked.addListener(function(tab){
chrome.tabs.create({url: "facebook.com", "active":true});
});
}
}
};
// Listen for any changes to the URL of any tab.
chrome.tabs.onUpdated.addListener(checkForValidUrl);
So, I go on google, click page action, in new tab opens facebook. I make new tab with google again, click page action and it opens 2 facebook-tabs. Its strange, because I need - 1 click on page action - 1 new tab. How to fix it?
Thanks.
The problem is that you're adding an event listener every time your tab changes.
Since you're calling checkForValidUrl every time a tab changes, chrome.pageAction.onClicked.addListener is also called every time a tab changes. Now your pageAction has two event listeners doing the same thing. You can verify this by changing tabs multiple times and see that it will open as many Facebook tabs as you have changed tabs.
To fix this, of course, you should remove the following from checkForValidUrl:
chrome.pageAction.onClicked.addListener(function(tab){
chrome.tabs.create({url: "facebook.com", "active":true});
});
and put it outside, for example, after you set up your listener for chrome.tabs.onUpdated.

Crossrider setPopup not callling more then once

I have a problem calling crossrider setPopup multiple times based on
some condition like if user is logged in then only show the Popup on
browser action click otherwise show a login popup.
But, it is calling only once after that.
function handler(evtXHR) {
if (invocation.ready State == 4) {
if (invocation.status == 200) {
//alert("successs : "+invocation.responseText);
if (invocation.responseText == "demo") {
//buttonState = true;`enter code here`
appAPI.browserAction.setPopup({
resourcePath: 'html/New popup.html',
height: 1000,
width: 1000
});
}
In general, calling setPopup more than once changes the content for the subsequent button click. However, having reviewed your code, I can see that there are several issues with the extension, for example, for correct operation the button must be enabled in the Settings > Browser Buttons (see introduction to browserAction and How to add a button to your extension).
I don't think StackOverflow is the appropriate forum to assist you in debugging the extension issues and therefore, invite you to email our support channel (support#crossrider.com) with the details you provided and I will be happy to assist you further

Resources