This question is also at sharepoint.stackexchange.com but has failed to get views or responses so I'm posting here.
I'm trying to set the zoom level of a Visio document which is shown through the Visio Web Service.
http://mysite/_layouts/VisioWebAccess/VisioWebAccess.aspx?id=/Shared%20Documents/MyDiagram.vdw
I want to use the 'fit to page' zoom level which is achieved by pressing the button on the right of the toolbar. My first thought was click the button via javascript, but didn't get immediate success and also stumbled across MSDN articles on Objects in the Visio Services JavaScript API, the Vwa.VwaControl.getActivePage Method and the Vwa.Page.setZoom Method.
I can successfully construct a VwaControl object
vwaControl = new Vwa.VwaControl("ctl00_PlaceHolderMain_VisioWebAccess");
but I get null when I call getActivePage() on this control.
I've tried constructing other VwaControl using other ids from the page but none of them are valid - I get an error like "VwaControl does not exist for id {0}". I've tried traversing down the tree from vwaControl._control._zoomControl._fitButton._clickDelegate but I don't know how to fire that delegate.
Has anyone implemented an 'auto zoom to fit' feature in the VisioWebAccess.aspx page?
See answer at sharepoint.stackexchange.com - the zoom and positioning is saved within the document, so set it there. I was unable to control the zoom using javascript.
If you follow the example on the getZoom documentation, which is to add a handler to 'diagramComplete', you can get a valid reference to the active page...
I.e.
function zoomVWAControl()
{
vwaControl= new Vwa.VwaControl("WebPartWPQ2");
vwaControl.addHandler("diagramcomplete", onDiagramComplete);
}
function onDiagramComplete()
{
try{
vwaPage = vwaControl.getActivePage();
var zoomLevel = vwaPage.getZoom();
vwaPage.setZoom(Number(200));
}
catch(err){
alert(err);
}
}
Related
I’ve done a lot of research on and off Stackoverflow and I’ve read many posts and tried many suggestions to no avail.
So I am posting a new question since all the answers that I have read haven’t led me to a solution.
Issue: I need to close all tabs that I’ve opened via window.open() function.
My original implementation uses LocalStorage to keep track of tabs that have been open via the parent window.
When a link is clicked (in the parent window), a new tab is open via window.open(“url”, “uniqueId”);
I store the uniqueId in an array in localstorage which in essence is my list of tabs.
To close all the windows that I opened, I loop through the localStorage array (the tablist).
I get the window uniqueId which I use to reference and close the (child) window…
// (localstorage) myTabList': [“window1”,” window2”,” window3”,” window4”]
var arr = JSON.parse(localStorage.getItem(‘myTabList'));
for (var i = 0; i < arr.length; i++) {
newWindowObj = window.open('', arr [i]);
if (newWindowObj != null) {
newWindowObj.close();
}}
This works like a charm as long as the (child) window.name doesn’t change.
Unfortunately, the names of some of the (child) tabs do change.
I have no control over the child tabs.
Think of if as if I open Google or Bing website in a child tab and the name changes.
Parent window (tab)
link A <a href=”#” #click=”window.open(‘http://www.google.ca’,’GOOGLE’) ”>Google</a>
link B <a href=”#” #click=”window.open(‘http://www.bing.com,’BING’)”>Bing</a>
I should point out that the tabs that change names load 3rd party web apps that are cross domain.
My app (parent tab web app) is a Vue 2.x project. Since the implementation described above doesn’t work as desired when a window name changes, I need a different solution.
I thought I could persist the tabs (window object) in an array of windows using the “vuex-presistedstate”.
If I use simple objects with Strings (just for testing purposes) to store data, all works flawlessly. e.g. storing objects containing String properties in an array {“url”:’http;//www.google.com”, “name”: “GOOOGLE”}, {“url”:’http;//www.bing.com”, “name”: “BING”}
But I run into issues when I try to store actual window objects.
var myTabList = [];
var newWinRef = window.open(“url”, “uniqueId”);
myTabList.push(newWinRef);
The storage of the window seems OK… based on the console output.
But it’s followed by this message.
Error in v-on handler: "TypeError: Converting circular structure to JSON
-- starting at bojec with constructor 'Window'
-- propery 'widow' closes the circle
So this solution doesn’t works very well either.
All I am trying to do is to open a window via window.open and persist some info about the newly opened windows / tab so that I can identify the tab(s) and call window.close() to close the child tab.
Any suggestions would be much appreciated.
Thank you!
I'm having difficulties to add an HyperLink to my Word Document using the Javascript API. I've look to Doc and I can't find any hints how to accomplish my duty...
Here is my Question: What is the best way to add an HyperLink inside a Word Document using the Javascript API.
And Here is what I tried:
Word.run((context: Word.RequestContext) => {
var range = context.document.getSelection();
context.load(range, "hyperlink");
return context.sync().then(() => {
range.font.highlightColor = '#FFFF00';
range.hyperlink = "C:\My Documents\MyFile.doc";
}).then(context.sync);
});
I've added the highlightColor just to have a visual that my changes are being sync. Everything seems fine but the Hyperlink property is not being updated. Am I missing something?
And If you guys are wondering what's this syntax, I'm using TypeScript.
Good, if you don't mind i will reply in JavaScript :)
Setting a hyperlink to a file must work (provided that the file exists :) ). I have this simplified example working successfully, btw you don't need to load the range for setting this.
Also hyperlinks is now supported as preview, so please make sure that you are running an updated (latest) version of Word (go file and install updates) and most importantly make sure you are using the preview CDN for Office.js which is here: https://appsforoffice.microsoft.com/lib/beta/hosted/office.js
Word.run(function(context) {
// Insert your code here. For example:
context.document.getSelection().hyperlink = "C:\My Documents\MyFile.doc";
return context.sync();
});
How can I communicate from a JavaScript code of a webpage to the main code of the add-on?
For example, something like this: If some element is clicked, in the corresponding event handler of the page script, which is the syntax that can be used to send some message to the main code?
Specifically, something like this, where the frame now must be replaced by a generic webpage. Is it possible?
Edit: I have tried the suggested code, but how I had said, the application returns this error:
console.error: sherlock:
Message: ReferenceError: document is not defined
Stack:
A coding exception was thrown in a Promise resolution callback.
See https://developer.mozilla.org/Mozilla/JavaScript_code_modules/Promise.jsm/Promise
Full message: ReferenceError: document is not defined
Previously my question, I had infact tried something similar without any effect.
Yes it is possible.
document.onload = function() {
var elementYouWant = document.getElementById("someID");
elementYouWant.onclick = console.log("Yup.. It was clicked..");
};
Reference.
The answer to the question is not as trivial as it may seem at first sight. I had also thought of a logic of the type described in the Pogrindis' response.
But here, in the case of interaction between the main script (i.e. that of the add-on) and generic script of arbitrary documents, the pattern is different.
In summary, the interaction takes place in this way:
It is required the API page-mod.
Through the property includes of the object PageMod you create a reference to the document, specifying the URI (wildcards are allowed).
Via the contentScriptFile property it is set the URL of the .js file that will act as a vehicle between the main code and that of the document.
Here's an example that refers to the specific needs of the context in which I am. We have:
an add-on code (the main code);
a Sidebar type html document (gui1.html) loaded in the file that I
use as a simple UI (I advise against the use of Frames, since it does
not support many typical HTML features - eg the click on a link,
etc.) containing a link to a second document (gui2.html) which will then
be loaded into the browser tab (I needed this trick because the
Sidebar does not support localStorage, while it is necessary for me);
a script in the document.
We must create an exchange of information between the two elements. In my case the exchange is unidirectional, from the page script to the main one.
Here's the code (main.js):
var pageMod = require("sdk/page-mod");
pageMod.PageMod({
include: "resource://path/to/document/gui2.html",
contentScriptFile: data.url("listen.js"),
onAttach: function(worker) {
worker.port.on("gotElement", function(elementContent) {
console.log(elementContent);
});
}
});
and in the html page script:
<script type="text/javascript">
[...]
SOWIN = (navigator.userAgent.toLowerCase().indexOf("win") > -1) ? "win" : "nix";
if (SOWIN == "win") {
window.postMessage("win","*");
} else {
window.postMessage("Linux","*");
}
[...]
</script>
Finally in the JS file (listen.js) to be attached to the page script:
window.addEventListener('message', function(event) {
self.port.emit("gotElement", event.data);
}, false);
This is just a small example, but logic I would say that it is clear. The uploaded content scripts are not accessible directly from main.js (i.e. the add-on), but you can create a bidirectional communication through the exchange of messages. To achieve this we have to put ourselves in listening the event Attach of the page-mod. Then, it is passed a worker object to the listener; that worker may be used by the add-on for the exchange of messages.
Here are the references to have an exhaustive picture:
Interacting with page scripts
Communicating with other scripts
page-mod
port
Communicating using "port"
postMessage
Communicating using postMessage
I am using HTML5 Local Notifications in Blackberry 10 (Higher Version BB z10) using webworks 1.0
And it works fine for Me.
The code used look like this.
var n = new Notification("MyMessage", {
'body' : content.message,
'tag': content.chatid,
'target' : "MyMessage",
'targetAction' : "bb.action.OPEN"
});
The link of this api reference is here
Blackberry Webworks Notification
Now there is one more field as ""
payload: Payload to send to the invoked app. Data must be Base64 encoded. Value is passed on to the Invocation Framework as data.
This to open a specific html page based on the notification you click.
I am not able to use it correctly. Also blackberry support forms do not give reply or any sample for this.
Question I asked in Blackberry Support Forums
I think there is a simpler way of achieving what you are trying to do.
First of all allow me to point you to the notification sample:
https://github.com/blackberry/BB10-WebWorks-Samples/blob/master/notify/.
To answer your specific query you need to bear in mind 2 things in the following order:
(1). The app needs to be invokable so you need to modify the config.xml and the index.html respectively:
config.xml
<rim:invoke-target id="com.myApp.entrypoint">
<type>APPLICATION</type>
<filter>
<action>bb.action.OPEN</action>
<mime-type>text/plain</mime-type>
</filter>
</rim:invoke-target>
where "id" is your unique ID (ie. nobody else should be using that)
index.html or index.js
document.addEventListener("invoked", onInvoked, false);
add the above after the system has fired the "deviceready" event.
The "onInvoked" function will look like:
function onInvoked(data) {
var pageToOpen = data.URI;
//do something with pageToOpen now
}
(2). Your notification will need to have the attribute "payLoadURI" set to the html page that you want to open. I'm thinking It will be something like
local:///myPage.html
This "myPage.html" it's what your "pageToOpen" variable will receive and at that stage you can push the right HTML fragment to the top.
I hope it helps.
P.S. this has been tested with WebWorks 2.0 so I would advise you to upgrade for a better experience.
I've an extension, and an XUL file inside it (let's call it A). XUL file contains an <iframe>, where is loaded some web page (let's call it B). B is loaded from the different domain.
A is parent to B. I want to send a message from within B to A using window.parent.postMessage().
I'm getting the following exception:
... permission denied to B to call method ChromeWindow.postMessage
How to fix that error? If there is no way to do that, how can I pass message from B to A?
I am using Firefox 16.0.1 under Windows 7.
I had a very similar problem,
it's just I had a html-popup (local) that couldn't send 'postMessage' to my xul-background-task.
I think I got it to work,
strangely enough by initiating a MessageEvent of my own (the very same thing postMessage does)
but with a (I believe obsolete) fallback.. in short: I brewed something together from MDN and other sites ;)
My script in the content:
var Communicator =
{
postMessage: function(data)
{
// We need some element to attach the event to, since "window" wont work
// let's just use a fallback JSON-stringified textnode
var request = document.createTextNode(JSON.stringify(data));
// and as always attach it to the current contentwindow
document.head.appendChild(request);
// Now let's make a MessageEvent of our own, just like window.postMessage would do
var event = document.createEvent("MessageEvent");
event.initMessageEvent ("own_message", true, false, data, window.location, 0, window, null);
// you might want to change "own_message" back to "message" or whatever you like
//and there we go
request.dispatchEvent(event);
}
}
And instead of window.postMessage(data) now use Communicator.postMessage(data)
that's all!
Now in my overlay there's nothing but our good old
addEventListener('own_message', someMessageFunc, false, true);
//or maybe even "message" just like originally
Hopefully this will work for you, too (didn't check that on iframes...)
You should check the type of iframe B
Edit:
Apparently you must flag your chrome as contentaccessible, and take into consideration the security.
Just posting in case someone faced the same problem.
Succeeded in posting message from within B to A using events as described here.
But it is not answer, because window.parent.postMessage() still doesn't work as intended.