I'm trying to load information from a .xml file (located in a .kmz archive) into the description of a placemark using javascript. The goal is to display the information from the .xml file in an html table in the description. I've gotten everything working, with the exception that I can't seem to access the .xml file from the .kml file. I'm trying to use an XMLHttpRequest() to load the file from the .kmz. It works just fine as an html file, but when i put the html/javascript into a description tag of the .kml, nothing loads at all.
Does anyone know if this is even possible to do? If so, how? If not, any other suggestions?
Thanks in advance for the help!
Is this using the Google Earth API? If so, note that script tags, amongst others, are stripped out by default. You can work around this if needed as described at https://developers.google.com/earth/documentation/balloons#getballoonhtmlunsafe
If this is KML being loaded into the Google Earth client, javascript is allowed (with the exception of things like alerts which bring up a browser dialog).
However it's quite possible, for example if you are loading a separate KMZ in your XHR request, amongst a variety of other reasons, that you're getting a cross domain error (basically because you'll be loading a local file with file:// versus http://). To test this, I would recommend hosting the XML on a server somewhere, and trying to see if that works.
If so, but it does not work locally, please paste a link to your KMZ, or at least paste your main KML within the KMZ, and the associated file structure within the KMZ.
Related
I have been doing a lot of research and have been unable to find an answer to my exact question. I understand that having a google chrome extension that can write to local user files would be a major security breach and thankfully isn't possible. However in my extension is a .json file that is used to make a HTML webpage with links via JavaScript. The JS reads the .json file and inserts the lines of code on the html page. I am attempting to make a user interface that allows them to update and edit the .json file that is inside the extension in order to add new lines of code to the webpage, but have been unable to find anything that could make this work due to security issues. I was thinking that since the file is in the extension users should be able to modify it.
If that was confusing here is a flow of what I want to happen and where it is not working:
Works:
Users clicks on button that takes them to a webpage hosted in the extension -> when page is loaded, the javascript runs -> the JS looks at a .json file in the extension using an XMLHttpRequest, parses the data, and then inserts it into the html -> The user now see's the content that was contained in the .json file on the html page.
Doesn't work:
After this I would like to have an interface that will allow the user to edit this .json file in order to update the page as they see fit, all in the extension itself.
If it was just me using this extension I could simply use the chrome storage api's available, however this is for my team at work, who are wanting to make edits as we need. Which means we will all be editing the same .json file.
Any information regarding this would be very beneficial. Even if it's as simple as it can't be done. Either way manually editing the .json file without a simple UI is much easier than editing the html directly.
Thanks in advance!
Posts/Articles I have looked at regarding this question:
Access Local Files using a Google Chrome Extension
https://developer.chrome.com/extensions/storage
Local file access with javascript
Allow Google Chrome to use XMLHttpRequest to load a URL from a local file
So my ultimate problem is that I have a SharePoint list where each list item may have multiple image attachments. I am looking to scrape the list using PowerShell so that I can backup all the images.
I am able to access each item's page in the list because of similarities in the URL, but I am unable to extract the attachments. This is because the filename is non-determinant. Unfortunately, I don't seem to be able to parse the info with Invoke-WebRequest because it brings back the HTML of the page, which does not list the file attachments.
Instead, the file attachments can be viewed when you use the 'Inspect page source' button, and which I believe is because they are inside a JavaScript function.
So, my question is - Can I get each file in a page's attachment from the JavaScript function so that I can scrape the page? Also - am I interpreting this problem correctly, and are there any other ways to solve this problem?
Please note: I don't have access to SharePoint server dlls including Microsoft.Sharepoint.dll, so I can't use Classes from that dll (unless they might be easily imported without having to install the whole library).
Here is a photo of where the source changes. I believe this is where HTML ends and Javascript begins:
And the highlighted lines in this file shows the information that I am looking to parse from the page's source information so that I can form the URL to download the image attachments:
I have a KML file that I am trying to load into Google maps. It zooms somewhere in the water with no route trace. This is the code I am trying:
var kmlLayer = new google.maps.KmlLayer(kml);
kmlLayer.setMap(this.googlemap);
"this.googlemap" has a Google map object. It is very simple example, but maybe I am missing something or my KML is not in the right format. My KML file can be download here: http://temp-share.com/show/gFHKdyG0Y. Can anyone help?
Google Map needs to be able to access this KML file direclty, in other words, your KML file must be publicly available, and must end with .kml or .kmz extensions (I believe).
To make sure the KML file itself is correct, you can always go to maps.google.com and put the URL in the search bar, it should be automatically recognized and rendered.
As Bill says, the KML file needs to be publicly downloadable, however The URL you linked to in the question abov does not link directly to the file itself, it links to an HTML page that you can visit to download the file. You may have to try a different service, as it doesn't appear that you can download directly from that location without going through the intermediate page.
You will know you are using the right link when you paste the link into the browser, and it immediately prompts you to download the file.
If you still have problems, make sure to post more of your code.
I have a web service that works through giving users javascript to embed in their code. Users can also place that code on other sites to make it work there. However I also need to allow users to create a blacklist of sites that the JS should not function on. For example, a competitor or an inappropriate site.
Is there a way to check where our JS files are being loaded from, and block loading or break functionality on a per account basis?
Edit: The javascript loads an iframe on the site, so another solution would be to somehow block certain domains from loading an iframe from our server, or serve different content to that iframe
Edit 2: We're also trying to avoid doing this from with the JS because it could be downloaded and modified to get pass the block
Inspecting the url of the page
Yes, the javascript file, when it starts executing, can inspect window.url and see if the url of the main document is ok.
To see where the script was loaded from
It can also go through the dom, looking for the script node which brought in the javascript file itself and see from where the JS was loaded.
However
Anyone can load the javascript into a text editor, then change it to eliminate the tests, then host the modified JS on their own server. Obfuscating or minimizing the JS can slow someone down but obscurity is not security.
One thing you could do is have the javascript load another javascript file. That you serve from the server at a given url. The trick here is that that url will not go to a file but to a server end point that will return a javascript file. The you have that endpoint check for the routes for that user and decide if it will return the javascript you want to work or an error javascript of some kind.
This blog shows how to do it in php.dynamic-javascript-with-php
Lets say for example i have an google search results page opened in a window or a tab in firefox.Is there a way i can retrieve the html code of that tab or window using javascript?
I suppose that the webpage html is saved temporarily somewhere in computer memory.
Can i load the webpage using memory saved address?
Is there a way for javascript to read html files saved in the same folder as the original?For example i have saved the webpage in a folder on my computer.If i create an html file inside the same folder does javascript consider the saved webpage as the same domain?
No, you most certainly can't do that unless you control both pages. This would be a huge security hole.
There is a custom search API which may help if you specifically want to do Google searches. It appears to have a JSONP implementation which should let you make a cross-domain request, but I haven't tried it out so I'm not sure how well it works.