I want to allow users to create HTML, CSS, and JS files and preview them. I give them the option to preview the HTML file in a WKWebView. I do this by passing the whole HTML file as a string to the WKWebView's loadHTMLString function in my Swift code.
If someone writes <script src="index.js"></script> within their HTML file being previewed, I want that to work. Where will WKWebView look for the index.js file? Should I be writing all 3 files to a temporary directory in iOS and letting WKWebView simply load the HTML file from there?
Related
I want to embed an "HTML viewer" inside of my Electron app, which would be fed with HTML contained in a string. My application automatically generates HTML code, which I want to visualize rendered as it would be displayed in a web browser.
I have seen there is a component called <webview> but it loads the HTML content from an external site via URI.
Is it possible to feed this <webview> component (or any other) with HTML from a simple string to achieve my goal?
Check this in electron repository
https://github.com/electron/electron/issues/1146
You can go with data uri, if you don't need JavaScript.
If you need JavaScript, there is a workaround. You can save the html string as a html file and load the html file in electron
Once the window is closed, you can delete the html file
According to the tutorial, there are two parts of an electron app - the entry main.js file and index.html.
Do I have to include main.js as a script in the html file
How do I trigger events in the view html file to affect the state of the js app and vice versa ? How do they both communicate basically ?
You are mixing up a couple of things.
main.js is the first file called when your run your application. Before everything else. It does not run any front-end code.
Usually, in it, you create with the BrowserWindow API a chromium window, then load an .html file in it. (index.html for example).
Then, your index.html, you can call for every front JS code you want, or CSS or whatever. For example you can add there a <script src="myapp.js"></script>, which will run front-end code.
It is important to understand the difference between the main process (back-end) and the render process (front-end).
See the quick start guide that explains that very well.
I have an ASP.NET MVC3 application. In my application, I need to be able to render external HTML pages. These HTML pages are stored in a simple file structure, with images, CSS and JS files stored in folders. Basically opening the HTML file will render the page as it should be rendered. What I want is to be able to render this page programatically.
So far, I have tried stuff like this:
Response.WriteFile(path)
return new FilePathResult("~/Path", "text/html");
The problem is that the resources (images, CSS and JS files) do not get loaded, since I only load the html source.
What can I do to be able to correctly render the html file with the other included files?
P.S.: I know that this functionality can be a security hole in my application. Thanks!
Edit: As Darin pointed out, I can use an iframe to place the rendered HTML page in my view. This is what I am currently using, but I want to implement a more secure solution, a solution that wouldn't allow access to the actual HTML page.
What can I do to be able to correctly render the html file with the other included files?
You could use an iframe:
<iframe src="/somepage.html"></iframe>
The return new FilePathResult("~/Path", "text/html"); should also work, it's just that the static resources referenced in this HTML page (CSS, javascript, images, ...) need to be relative to the current url or absolute urls (which is more difficult if they are static HTML).
I am using ASP.NET MVC3. Adding a web project, it gives me all the files required for jquery to run.
It gives me Content Folder and some folders for storing css and Images.
It also gives me Scripts folder, where I can have my .js files.
Whenever I want to download some custom JQUERY UI controls, It gives me a zip file which has different folders and scripts.
How do I map them so that, I am not keeping too many jquery files in my project.
For example, I want to use DatePicker Jquery UI, I go to jquery site and download them and it gives me a ZIP File which has various folders.
There is folder called development again it has got all the files.
If I wan to go for timepicker, I think there is only a CSS difference between timepicker and datepicker.
Timepicker needs slider. So I am not sure do i need to reference jqueryslider.js in my Layouts file.
Please shed some light on this mapping of downloaded files and already existing files in MVc3?
if have to include new Jquery UI Control, What should be the changes, is it just in .js file, images folder, or css folder.
I personally think its only css and images, please correct me.
Thank you.
All you need to do is add the content in the js folder to the scripts in your Scripts folder and copy everything from the css\\ folder into the Content folder of your MVC application.
Once you have done this, you simply add the following references to the _Layout file in your Shared folder (just modify to match your version of JQuery and the correct version of your JQuery-UI download):
<link href="#Url.Content("~/Content/jquery-ui-1.8.18.custom.css")" rel="stylesheet" type="text/css" />
<script src="#Url.Content("~/Scripts/jquery-1.7.1.min.js")" type="text/javascript"></script>
<script src="#Url.Content("~/Scripts/jquery-ui-1.8.18.custom.min.js")" type="text/javascript"></script>
Just remember to keep the reference to your JQuery library (jquery-1.7.1.min.js in the example above) before the reference to the JQueryUI scripts.
-- Kindly mark as the answer if this has been helpful
Does rails disable use of a flash .swf file in a rails app by default, and is there a way to make it work?
I am trying to integrate the Wimpy Button MP3 player into pages of my Rails 3 app.
The MP3 player consists of a two files, wimpy_button.swf and wimpy_button.js. They need to go in the same directory.
I put them both in my /public/javascripts directory (the .js assumes the .swf is in the same directory)
I added the js to my layout (and verified the script src= is in my resulting html files)
= javascript_include_tag "wimpy_button.js"
(I also tried just hardwiring it with;)
<script src="/javacripts/wimpy_button.js" type="text/javascript"></script>
On a page, whereever I want an MP3 player button I have this javascript:
<script language="JavaScript" type="text/JavaScript">
writeWimpyButton("http://example.com/url_to_audio.mp3", "20", "20", "&displayRewindButton=yes");
</script>
On my static test pagein /public/testplayer it works fine.
But on any of the active pages, an empty space is where the player icon should be.
I assume the external content is being blocked by some security setting on rails?
Those files don't need to be in the same directory. Not sure which version of Rails 3 you're using, but you might be having a fight with the asset pipeline here.
Read more at: http://guides.rubyonrails.org/asset_pipeline.html
Then, put your swf in app/assets/flash and your js in app/assets/javascripts. Files will be available from your browser at /flash and /javascripts. You may need to edit the javascript to reference the correct location of your swf file.