I am pretty new to Javascript/html5. I am basically working off code provided in Rbon Nixon's book (4th Edition, Learning PHP, MySQL and Javascript...). Example 22-2 of which is about "displaying the map at a user's location".
I am getting caught in the if part of the following code snippet:
<script>
if (typeof navigator.Geolocation=='undefined')
alert("Geolocation not supported.")
</script>
Superficially, it seems quite obvious that I should enable geolocation int eh browser for localhost. I am using chrome (Version 60.0.3112.113). But when I go to Settings >> Advanced >> Content Settings >> Location
the ask before accessing option is enabled. and then there are the Block and Allow sections. But it does not give me an option to add localhost. How do I enable it so that I can use geolocation in my code and test it on my machine?
I'm facing problems when the client internet connection is unstable. If disconnections occur during the loading process google maps services won't work even when the connection comes back.
The difficulty with phonegap compared to a normal browser is that there is no "reload page" button the user can hit if the page didn't load properly. We thus have to ensure a 100% safe load.
If you follow the instructions provided by Google to implement google maps javascript api in your phonegap app, the loading process will crash at three different steps if the client connection is unstable.
Each crash is independent and a bit complex to explain, so i created sub questions : first crash, second crash, third crash
I also created that file so that anyone can reproduce the crashes.
I suspect that the problem partly comes from google's script, but there is probably a work around i didn't see.
Not sure at all that this could help but I faced an issue regarding multiDex when I tryed to use google map api when adding this code in file build-extras.gradle my google map crash was solved :
android {
defaultConfig {
minSdkVersion 15
targetSdkVersion 23
multiDexEnabled true
}
dexOptions {
javaMaxHeapSize "2g"
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
}
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
What I understood was that using simple Dex I can only implement 65000 method but the google api add lot of them.
Building Apps with Over 65K Methods
Not sure this could help or not, let me know if I should delete this answer.
I'm creating a watch face for my Gear 2 Neo (using Tizen Wearable SDK), and I've spent hours looking (with no luck) for a way to determine if the bluetooth is enabled or not (and if possible if it's connected).
I've tried looking at the Tizen.SystemInfo API documents, but I can't find anything. I've even tried tizen.systeminfo.getPropertyValue(); with "BLUETOOTH" / "NETWORK" as the property name, but this doesn't work. It seems the Tizen.Bluetooth namespace isn't usable either.
I know there must be a way, as I have seen several watch faces out there that are able to get the status.
Is anyone able to help me out / point me in the right direction?
Edit:
Using tizen.bluetooth.getDefaultAdapter(); returns the following: "The application does not have the privilege to call this method"
Yes, it is possible.
To get the bluetooth status, you need to first get the defaultAdapter using following API
var blueAdapter = tizen.bluetooth.getDefaultAdapter();
console.log(blueAdapter); // To log the object
/* Output of above log
BluetoothAdapter
address: ""
name: ""
powered: false
visible: true
*/
if (blueAdapter.powered) {
// Bluetooth is on, you can off using
blueAdapter.setPowered(false);
} else {
// Bluetooth is off, you can switch on using
blueAdapter.setPowered(true);
}
Don't forget to add the privilege in config.xml of your app.
<tizen:privilege name="http://tizen.org/privilege/bluetooth.gap"/>
Note: Whenever you try to use platform, you need to provide the corresponding privilege in your apps config.xml file
I am developing a phonegap application using phonegap build (therefore ALL in pure js and html, no native languages).
In my page, i have some geo uri links (http://en.wikipedia.org/wiki/Geo_URI ) that are cliccable (they represent coordinates of markers in a map).
Now, if the mobile device has installed and associated with this type of files an app (usually a gps navigator or the like), they open and launch the associated application as they should.
My issue is that I don't want to show the clickable link (the button appears in the infowdindow of the marker) if the device has no app capable to open them.
In native android code, you have the query-intent command for this. Does anyone know how to verify this in pure phonegap js?
Ty!
D.
I have been asked for code: The only code that is relevant here is the following, which computes the html code to embed in the infowindow of the marker:
var computePathString=<a href='geo:"+area['marker']['position'].lat()+",
"+area['marker']['position'].lng()+"'>Route</a>;
Which translates to the following html:
<a href='geo:45.557,9.1523'>Route</a>
Which works great on click IFF the device has an associated app (usually a gps navigator), but else does nothing on click. I need to achieve something similar to the query intents of android:
PackageManager packageManager = getPackageManager();
List<ResolveInfo> activities = packageManager.queryIntentActivities(intent, 0);
boolean isIntentSafe = activities.size() > 0;
only, in native phonegap js.
Is it possible to to take a screenshot of a webpage with JavaScript and then submit that back to the server?
I'm not so concerned with browser security issues. etc. as the implementation would be for HTA. But is it possible?
Google is doing this in Google+ and a talented developer reverse engineered it and produced http://html2canvas.hertzen.com/ . To work in IE you'll need a canvas support library such as http://excanvas.sourceforge.net/
I have done this for an HTA by using an ActiveX control. It was pretty easy to build the control in VB6 to take the screenshot. I had to use the keybd_event API call because SendKeys can't do PrintScreen. Here's the code for that:
Declare Sub keybd_event Lib "user32" _
(ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Public Const CaptWindow = 2
Public Sub ScreenGrab()
keybd_event &H12, 0, 0, 0
keybd_event &H2C, CaptWindow, 0, 0
keybd_event &H2C, CaptWindow, &H2, 0
keybd_event &H12, 0, &H2, 0
End Sub
That only gets you as far as getting the window to the clipboard.
Another option, if the window you want a screenshot of is an HTA would be to just use an XMLHTTPRequest to send the DOM nodes to the server, then create the screenshots server-side.
Another possible solution that I've discovered is http://www.phantomjs.org/ which allows one to very easily take screenshots of pages and a whole lot more. Whilst my original requirements for this question aren't valid any more (different job), I will likely integrate PhantomJS into future projects.
Pounder's if this is possible to do by setting the whole body elements into a canvase then using canvas2image ?
http://www.nihilogic.dk/labs/canvas2image/
A possible way to do this, if running on windows and have .NET installed you can do:
public Bitmap GenerateScreenshot(string url)
{
// This method gets a screenshot of the webpage
// rendered at its full size (height and width)
return GenerateScreenshot(url, -1, -1);
}
public Bitmap GenerateScreenshot(string url, int width, int height)
{
// Load the webpage into a WebBrowser control
WebBrowser wb = new WebBrowser();
wb.ScrollBarsEnabled = false;
wb.ScriptErrorsSuppressed = true;
wb.Navigate(url);
while (wb.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); }
// Set the size of the WebBrowser control
wb.Width = width;
wb.Height = height;
if (width == -1)
{
// Take Screenshot of the web pages full width
wb.Width = wb.Document.Body.ScrollRectangle.Width;
}
if (height == -1)
{
// Take Screenshot of the web pages full height
wb.Height = wb.Document.Body.ScrollRectangle.Height;
}
// Get a Bitmap representation of the webpage as it's rendered in the WebBrowser control
Bitmap bitmap = new Bitmap(wb.Width, wb.Height);
wb.DrawToBitmap(bitmap, new Rectangle(0, 0, wb.Width, wb.Height));
wb.Dispose();
return bitmap;
}
And then via PHP you can do:
exec("CreateScreenShot.exe -url http://.... -save C:/shots domain_page.png");
Then you have the screenshot in the server side.
This might not be the ideal solution for you, but it might still be worth mentioning.
Snapsie is an open source, ActiveX object that enables Internet Explorer screenshots to be captured and saved. Once the DLL file is registered on the client, you should be able to capture the screenshot and upload the file to the server withing JavaScript. Drawbacks: it needs to register the DLL file at the client and works only with Internet Explorer.
We had a similar requirement for reporting bugs. Since it was for an intranet scenario, we were able to use browser addons (like Fireshot for Firefox and IE Screenshot for Internet Explorer).
This question is old but maybe there's still someone interested in a state-of-the-art answer:
You can use getDisplayMedia:
https://github.com/ondras/browsershot
The SnapEngage uses a Java applet (1.5+) to make a browser screenshot. AFAIK, java.awt.Robot should do the job - the user has just to permit the applet to do it (once).
And I have just found a post about it:
Stack Overflow question JavaScript code to take a screenshot of a website without using ActiveX
Blog post How SnapABug works – and what they should do
I found that dom-to-image did a good job (much better than html2canvas). See the following question & answer: https://stackoverflow.com/a/32776834/207981
This question asks about submitting this back to the server, which should be possible, but if you're looking to download the image(s) you'll want to combine it with FileSaver.js, and if you want to download a zip with multiple image files all generated client-side take a look at jszip.
You can achieve that using HTA and VBScript. Just call an external tool to do the screenshotting. I forgot what the name is, but on Windows Vista there is a tool to do screenshots. You don't even need an extra install for it.
As for as automatic - it totally depends on the tool you use. If it has an API, I am sure you can trigger the screenshot and saving process through a couple of Visual Basic calls without the user knowing that you did what you did.
Since you mentioned HTA, I am assuming you are on Windows and (probably) know your environment (e.g. OS and version) very well.
If you are willing to do it on the server side, there are options like PhantomJS, which is now deprecated. The best way to go would be Headless Chrome with something like Puppeteer on Node.JS. Capturing a web page using Puppeteer would be as simple as follows:
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
await page.screenshot({path: 'example.png'});
await browser.close();
})();
However it requires headless chrome to be able to run on your servers, which has some dependencies and might not be suitable on restricted environments. (Also, if you are not using Node.JS, you might need to handle installation / launching of browsers yourself.)
If you are willing to use a SaaS service, there are many options such as
Restpack
UrlBox
Screenshot Layer
A great solution for screenshot taking in Javascript is the one by https://grabz.it.
They have a flexible and simple-to-use screenshot API which can be used by any type of JS application.
If you want to try it, at first you should get the authorization app key + secret and the free SDK
Then, in your app, the implementation steps would be:
// include the grabzit.min.js library in the web page you want the capture to appear
<script src="grabzit.min.js"></script>
//use the key and the secret to login, capture the url
<script>
GrabzIt("KEY", "SECRET").ConvertURL("http://www.google.com").Create();
</script>
Screenshot could be customized with different parameters. For example:
GrabzIt("KEY", "SECRET").ConvertURL("http://www.google.com",
{"width": 400, "height": 400, "format": "png", "delay", 10000}).Create();
</script>
That's all.
Then simply wait a short while and the image will automatically appear at the bottom of the page, without you needing to reload the page.
There are other functionalities to the screenshot mechanism which you can explore here.
It's also possible to save the screenshot locally. For that you will need to utilize GrabzIt server side API. For more info check the detailed guide here.
As of today Apr 2020 GitHub library html2Canvas
https://github.com/niklasvh/html2canvas
GitHub 20K stars | Azure pipeles : Succeeded | Downloads 1.3M/mo |
quote : " JavaScript HTML renderer The script allows you to take "screenshots" of webpages or parts of it, directly on the users browser. The screenshot is based on the DOM and as such may not be 100% accurate to the real representation as it does not make an actual screenshot, but builds the screenshot based on the information available on the page.
I made a simple function that uses rasterizeHTML to build a svg and/or an image with page contents.
Check it out :
https://github.com/orisha/tdg-screen-shooter-pure-js