I am trying to learn the UI Service in order to build my own form (panel). I tried copying and running the example panel, but I can't get it to work (the code is below). The panel will not pop up. Do I have to set something in my browser? Please help.
function doGet() {
// A script with a user interface that is published as a web app
// must contain a doGet(e) function.
// Create the UiInstance object myapp and set the title text
var myapp = UiApp.createApplication().setTitle('Here is the title bar');
// Create a button called mybutton and set the button text
var mybutton = myapp.createButton('Here is a button');
// Create a vertical panel called mypanel and add it to myapp
var mypanel = myapp.createVerticalPanel();
// Add mybutton to mypanel
mypanel.add(mybutton);
// Add my panel to myapp
myapp.add(mypanel);
// return myapp to display the UiInstance object and all elements associated with it.
return myapp;
}
The doGet() function runs when the URL of your App is either first loaded in the browser, OR you refresh the page in your browser. If your App is a Stand Alone App (Not attached to a Sheet or a Doc) then you will have a file associated with that app in your Google Drive. The Apps Script file icon is a blue square with a white arrow pointing to the right.
If you double click that file, it should open up in your browser and run the doGet() function. You can also provide the URL of the App as a link.
But first you need to deploy it.
Click the icon of a cloud with an up arrow in it:
You'll be asked to name your project if you haven't done that already. Then, you'll get a pop up that looks like this:
Click Deploy
You'll get another pop up, . . . click 'Latest Code'. Your app will open up in the browser.
The code you supplied puts a button in the window labeled, 'Here is a Button'.
Related
I am trying to fix a bug in a Chrome extension. When the extension is installed an alert dialog containing the message "undefined" will be displayed seemingly at random. This does not happen when the extension is not installed.
There is not one call to alert, confirm, or prompt in the extension source code. How do I find out why the alert dialog is being displayed?
I have attempted adding the following code to one of the background scripts and to one of the content scripts.
var originalWindowAlert = window.alert;
window.alert = function() {
console.trace();
return originalWindowAlert.apply(window, arguments);
}
I have confirmed that this technique works when used in a webpage, but it is not working for the extension.
I have also built Chromium from source code and I am able to reproduce it but so far I have not been able to figure out how to determine the origin of the alert dialog. I have set a breakpoint in the RenderFrameHostImpl::RunModalAlertDialog function but I see no way to determine what caused the breakpoint to be hit.
I am getting desperate.
I asked this question on the Chromium Extensions Google Group. I got the following very useful response from Scott Fortmann-Roe.
If you do the following in a content script:
var originalWindowAlert = window.alert;
window.alert = function() {
console.trace();
return originalWindowAlert.apply(window, arguments);
}
I don't believe it will actually intercept alerts triggered by the page as you are overriding the content script's window.alert method which is different from the page's method (content script JS is isolated from page JS).
To modify the page's alert method you'll probably need to inject a script tag into the page. E.g. something along these lines in the content script:
let script = document.createElement('script');
script.textContent = `
var originalWindowAlert = window.alert;
window.alert = function() {
console.trace()
return originalWindowAlert.apply(window, arguments);
} `;
document.body.appendChild(script);
I am working to link an image in my Google Sheet document to a specific cell in another tab. I'm doing this by building a simple function that will do this. However, when I assign the function and then click on the image, I then get the error :
Script function "test" could not be found
When I run the function in the script manager interface, it works fine. It's when I try to actually use it in the sheet with the image.
Function Script :
function test()
{
Browser.msgBox("You clicked it!");
}
It turned out that the document owner had left their job and ownership rights had been moved to someone else. Can it matter ?
The error is : Here
Thank you very much,
Make sure the assigned function name does not include the () brackets. 😎
Did a little snippet just to demonstrate on how you might approach this:
I used the sample from HTML Service: Create and Serve HTML on creating a button (in your case it's image) which responds to a click event. I'm using a bound script.
//in bounds script, this integral function triggers as soon as you open the spreadsheet
function onOpen() {
SpreadsheetApp.getUi()
.createMenu('Dialog')
.addItem('Click Me', 'test')
.addToUi();
}
//Then I attached your test function
function test()
{
Browser.msgBox("You clicked it!");
}
And sure enough upon clicking the button, the test function triggered:
I have a requirement that we should be able to copy an image displayed in our application, to Clipboard and paste it outside (Like on Excel).
I was trying the below code snippet (Inside a button Click).
Clipboard.generalClipboard.clear();
var dataLoaded:Boolean = Clipboard.generalClipboard.setData(ClipboardFormats.RICH_TEXT_FORMAT,
byteArray, false);
The dataLoaded object is true, however it does not paste anything when tried on Excel or MsPaint.
Do we have any way to achieve this?
Thanks.
The code you are showing is not enough in itself to get a successful transfer. Like many other operations within the security sandbox of a FP app (web) this code can only respond to a direct user interaction. So your code without any valid context cannot work of course but if called within a mouse down listener for example (a true user generated mouse event, creating a fake mouseevent would still not work) it should respond correctly:
private function handleMouseClick(event:MouseEvent):void
{
Clipboard.generalClipboard.clear();
var dataLoaded:Boolean = Clipboard.generalClipboard.setData(ClipboardFormats.RICH_TEXT_FORMAT, byteArray, false);
}
I used Google map and visited a location and saved it as an html page by this I am able to view that location in future also with zoom functionality. Is it possible to save that location(map) in .pdf format instead of html format with zooming capability.
If yes how and if no then please answer why.
If you go to print that html file, the print dialog will pop up with the default printer. Click 'change' under the printer and choose 'Save as PDF'. You can zoom a pdf in adobe reader.
or (the long way)
Launch InDesign and create a new A4 landscape document. Now press F (Frame tool) on your keyboard and drag a frame with a size you wish to have for the map.
Go to Workspace settings (top right corner of InDesign) and change it to interactive for PDF. Go to Window → Interactive → Buttons. In InDesign you can create buttons very easily. Create any object and then right click and select Interactive - Convert to button.
To import a Google map to flash you need to download Google Map Component - map_1_18.swc.
In Windows 7 navigate to C:Program Files (x86)AdobeAdobe Flash CS6CommonConfigurationComponents. Then create a new folder there and name it Google. Store the .swc file there and then go to this page and follow the instruction to get the API key and save it. Your Flash is now set up to supports Google maps API.
Open the Components panel by pressing CTRL + F7 or click Window → Components in the menu. You should see the Google map library there. Drag and drop it to the Library panel.
Go to Layer panel in timeline and call it e.g. gmap. Open the Action panel (or Press F9) Windows → Actions. Now put there the code below to import the map:
import com.google.maps.LatLng;
import com.google.maps.Map;
import com.google.maps.Map3D;
import com.google.maps.MapEvent;
import com.google.maps.MapType;
import com.google.maps.View;
import com.google.maps.geom.Attitude;
// Creating map variable
var map:Map3D;
/ Creating map
create_map();
function create_map()
{
map = new Map3D();
map.key = "your api key";
map.setSize(new Point(stage.stageWidth, stage.stageHeight));
map.addEventListener(MapEvent.MAP_READY, onMapReady);
this.addChild(map);
}
function onMapReady(event:MapEvent):void
{
map.setCenter(new LatLng(48.207401,16.372805), 13);
map.setAttitude(new Attitude(20,30,0));
map.viewMode = View.VIEWMODE_PERSPECTIVE;
}
In order to create the marker, you need to put some ActionScript again. Go to ActionScript panel and copy the following code. Change the classes to match yours if necessary.
var c:Marker = new Marker(new LatLng(-33.925272,18.423557),
new MarkerOptions({icon:new capeTown()}));
map.addOverlay(c);
var p:Marker = new Marker(new LatLng(50.075651,14.431229),
new MarkerOptions({icon:new prague()}));
map.addOverlay(p);
var v:Marker = new Marker(new LatLng(48.206371,16.375122),
new MarkerOptions({icon:new vienna()}));
map.addOverlay(v);}
If you want to have control fly.to animations with acrobat buttons. Since we call ActionScript from Javascript, we use the function ExternalInterface.addCallback that will build bridge between SWF and Acrobat Javascript. Create a new action layer and put there something similar to this. It should have the same marker coordinates:
function pr(e:MouseEvent = null):void
{
map.flyTo(new LatLng(50.075651,14.431229),12,new Attitude(0,0,4),5);
}
ExternalInterface.addCallback("pr",pr);
function vn(e:MouseEvent = null):void
{
map.flyTo(new LatLng(48.206371,16.375122),9,new Attitude(0,30,3),5);
}
ExternalInterface.addCallback("vn",vn)
function cp(e:MouseEvent = null):void
{
map.flyTo(new LatLng(-33.925272,18.423557),3,new Attitude(0,30,-10),3);
}
ExternalInterface.addCallback("cp",cp)
With map.flyTo function you can control the following parameters: LatLng, Zoom, Attitude, Time.
Now open your InDesign file again, that we have already prepared. Select the frame that will serve as placeholder for the map. With placeholder selected press CTRL + D (File – Import) to place your SWF map. Open the media panel and check Play on Page Load on. Choose None for Poster option. Now you are ready to export it to interactive PDF. Go to File – Export or CTRL + E and select Adobe PDF Interactive.
Open the file in Acrobat. You have your interactive Acrobat buttons and your embedded Google map there. The buttons do nothing now, except for the rollover effect if you have created any. In the Interactive tab tools choose select object tool and double click on one of the buttons. In the windows that arrive go to Actions and from Select action dropdown menu select Run a Javascript, Then Press Add. In a a new windows that open again put the following code:
getAnnotsRichMedia(this.pageNum)[0].callAS(“pr”);
Press OK and close
Reference
You may want to have a look at the Static Maps API https://developers.google.com/maps/documentation/staticmaps/. It allows you to request 640x640 Static Maps and you can adjust the zoom accordingly by altering the parameter. You can either use coordinates or names of places, which will get geocoded for your request.
Here are a few examples with different zoom levels and map types:
640x640, Zoom 14, Terrain Map:
http://maps.googleapis.com/maps/api/staticmap?center=Eiffel+Tower&zoom=14&size=640x640
640x640, Zoom 18, Satellite: http://maps.googleapis.com/maps/api/staticmap?center=Eiffel+Tower&zoom=18&size=640x640&maptype=satellite
Be aware though that according to 10.1.2.(b) of the Terms of Use, you:
(b) No Direct Marketing. You must not print more than 5,000 copies of sales collateral
materials containing a screenshot of the Content for purposes of
commercial sales lead generation ("Direct Marketing") or incorporate
the Content as a core part of printed matter (such as printed maps or
guide books) that you redistribute for a fee. You must contact the
Google Maps API for Business sales team to obtain a direct license if
you desire to do either of the above.
I want to develop an extension that runs in the background and listens to keystrokes and stores them as a string in a variable. For example, if I have 5 tabs in a chrome browser window and I press a,b,c,d,e on each tab of the window; the final string should be abcde.
Could any please provide a sample code for this?
Help will be greatly appreciated.
You could add code like this to a content script:
var bodyElement = document.getElementsByTagName("body")[0];
bodyElement.addEventListener("keypress", function(e){
console.log(e);
console.log(String.fromCharCode(e.keyCode));
});
The body element must be loaded for this code to work, so use jQuery's $(document).ready(), or similar, or in the extension manifest set the run_at value for the script to document_end.