Can I run a application on MacOS from a local HTML site? - javascript

Is there a simple way to start programs on mac from html?
I made an html page with a text field and a number of buttons. The intention is that when a code (numbers) is entered, it is copied to the clipboard. Via the buttons (each of which must open an application) the desired app opens and paste the code into the application (search or something ...). I already made this in AppleScript, but the layout is not that nice. That is why I wanted to work with HTML / CSS. Is there a simple way to run programs on mac starting from html/ Javascript?

I'm not sure if this is what you're looking for, but on Macs you can define custom URL schemes that will launch script applications to handle data. See:
Launch Scripts from Webpage
Which is an AppleScript-specific discussion of this:
How To Create Your Own URL Scheme

I'm also not sure of what you are looking for exactly, however, if it is vanilla JS, you can open the HTML file in the browser, which will also let you use the JavaScript as long as it is imported properly.
To open the HTML file in the browser, you can go to the file in the Finder then right-click and select "Open with Chrome". If you prefer to use a different browser, you can open it with whatever browser you want.

Related

Is there anyway to get full rendered HTML code of any website (with JavaScript code included)?

Is there any way we get the full HTML source code of a website with JavaScript code (fetched from 3rd party) are also included in it?
I understand we can get using document.getElementsByTagName('html')[0].innerHTML but it will not include the 3rd party JS in the HTML code?
The reason for this question (based on my knowledge) is when the browser renders and create DOM then it should have all the required files so does anyone know where and how we can get that full HTML source code of any website?
Yes when the browser renders the page it does indeed fetch these resources, you can use the save option provided by the browser, by clicking right click, then save as, then save as a complete webpage.
If the previous does not work, then there are many tools, extensions, applications that provides this functionality and its easy to search for them.
If you want to save the html and its resources in one html file, you can save it as mhtml file, using this extension for example https://chrome.google.com/webstore/detail/save-webpages-offline-as/nfbcfginnecenjncdjhaminfcienmehn.

Launching an HTML file locally?

I am new to web development. I use Brackets to do my development in. My webpage works using the live preview in Brackets but when I launch the page outside of Brackets, my JS doesn't load.
What I am asking is, is there a way to launch a webpage (HTML, CSS, JS) without creating a server for it all?
Look for the html file in your file system. Right click and open it in a browser of your choice.
Right now, it seems like clicking that file will open it in Brackets for you, however html files are able to be rendered by browsers when they read the html code.
Yeap, just put your HTML/CSS/JS in the same location — or different locations — and make sure you map to them properly.
From there, just double click your index.html — or whatever you named your html file — and it should popup in your browser.

Change href of anchor tag through html/css

I have a webpage(say http://www.example1.com) which contains an anchor tag that points to a different website(say http://www.example2.com). I have to test it on testing servers (for which the urls are www.example1-test.com and example2-test.com) before publishing it. When the code is on example1-test.com then the link should point to example2-test.com and when it is on example1.com then it should point to example2.com.
But I cannot use JavaScript or manually change code while switching the servers. I can only use html and css. Is there a way to do this?
I know this is a weird question and css is used for styling and not to write logic but I cannot use JavaScript for this unless there is a way to enable JavaScript in the browser through some html tags.(say some meta tags,etc.)
I can put in two separate link pointing to respective example1.com and example2.com and do a show/hide depending on the environment but then the question is where do I put these conditions (cannot use JavaScript).
For testing I used to change my hosts file and redirect live domains to my test IPs on the internal network. I follow links and my browser thinks I'm hitting example2.com but actually my hosts file is pointing to the IP of example2-test.com and I see new functionality. When both go live I know visitors experience exactly what I've just tested but using live DNS.
Nowadays URLs in my applications are generated using routes and environments. I can specifically tell my framework that in development environments I expect URLs to be generated with XYZ base but behave differently in production.
Another option is Greasemonkey scripts. It is a browser plugin which executes scripts on command to manipulate pages, navigate, automate and more.
I can't think of a client-side way to achieve what you're looking for without the use of Javascript or browser plugins.

Rendering HTML local file with out browser or networking (lightweight)

I have had a lot of trouble trying to find information or possible examples of this being done.
I would like to render html in a window and take the js from the html and output that to a python code.
The Html is local and there will never be an internet connection for it to run off. Everythin i try shearch for possible answers everyone always seems to relate back to using some small lightweigh browser which in my case isn't an option to use.
Fort some more detail, I am running Selenium-Webdriver
(python) and Iceweasel(Raspberry Pi B+) to get the value of a element from a html page. So using a different browser isnt possible as the lightweight ones are not compatible with selenium. Using Selenium and Iceweasel takes in excess of 2 miunets to fully load up which for what i need it for is far to long.
I had a look into Awesomium but i think it lacks compatability with the Raspberry Pi.
My other thought was to use OpenGL to render the html but found no easy explained examples.
Currently looking into LibRocket, Berkelium and QWebView but again i dont think they will have anythin i need with the compatability i need.
EDIT:
Basically i want a Canvas capeable of rendering HTML to a screen using X11. On the HTML there will be buttons. I want those buttons to preform actions inside a python script.
The way i see it, a browser is basically a toolbar, a canvas and a lot of networking. I want to strip away as much of that as possible and just remain with the canvas.
First go to the directory that you has the local webpage. Than run python -m SimpleHTTPServer 8000. This will "render the html" in a window. Then view source and paste the javascript into a python file. Alternatively if you would like to automate piping the javascript into an out file you can use beautiful soup to select the javascript and write it to any file you want. Then manipulate it in python however you want.

Chrome Apps <a> tag not working

Its been a few years since I have worked on Chrome apps. I started messing around with making some simple examples to learn the new process. The problem is that I have found that using an <a> tag to change the html page that is loaded to another html page inside the packaged app will not work. I'm looking for different methods of changing the screen with retrieving user input (button click, link click. and so on). I have looked online and have found very little documentation about making chrome apps most examples show how to make a simple "Hello World" and how to publish it. Not many extensive tutorials beyond that. Just to clarify this app would be a real chrome app not a link to some site. all files would be packaged with the chrome application.
Chrome Apps are meant to be "single page apps", and cannot navigate links by design. <a> links should open in a regular browser window instead.
If you want to do "url routing" within your application to change views, you can just roll your own solution, but should probably use a framework to help you out instead.
Here are some examples:
Polymer
Angular
Ember
Meteor
Backbone
The list is extensive. There are likely many other stack overflow answers that compare each framework.
The DOM (Document Object Model) which represents the contents of a Chrome App window is initiated from an HTML file, but from that point on you can't change it by referencing any other file, which is what you're expecting navigation to do. (<a> elements that navigate to an external browser via a "target=_blank" attribute are perfectly OK.)
However, you are free to change the DOM from your JavaScript at runtime. If you like, set an event handler on the <a> element and change the DOM as you wish. If you want to change the DOM via HTML (not from a file), you might find the JavaScript method insertAdjacentHTML useful. Actually, you can get the HTML from a file, but you have to read that file yourself with the Chrome App file I/O API.
Advice in another answer to use a framework is, in my opinion, overkill. If you think of a Windows app, a Mac app, or any other kind of GUI-based app, you would never assume that you could just change the UI over to something completely different by referencing an HTML file. Think of a Chrome App as being similar to those technologies in that sense, and you'll be on the right track.

Categories