I have a simple react component. Assume it as the default animated logo when the app is created
I now need to inject this component on top of a webpage using my chrome extension. I know how to inject a html template code along with its css and js through a chrome extension
I tried npm run build to generate static files so as to inject all those through my extension.
But that doesn't work. When the built index.html is injected onto someother page, it doesn't render there. Its just injected as root and nothing inside is rendered
<div id="root"></div>
Is there a solution on how I can get the a pre rendered static html of my react component so that I can use it to inject through my chrome extension
<div id="root">
<img src="a.png">
<h1>Sample text</h1>
.....
</div>
Above is how I want the rendered html of that component needs to be
When the built index.html is injected onto someother page, it doesn't
render there. Its just injected as root and nothing inside is rendered
Did you inject just the index.html file? When you do npm run build there are other files as well that are generated and are needed for the index.html to work. Mainly the chunk.js file and css files.
They need to be in the same directory as the rendered index html file(You might have to replace the relative paths with absolute paths to make it work, if you are not able to put the files in the same directory).
Further reference: https://create-react-app.dev/docs/production-build
Related
In examples like this we have the v-html directive to dynamically render the raw html into the dom. I am in need of a way to insert a raw script before the entire lifecycle begins its magic. This is because I am working with a macro (auth0).
<!doctype html>
<html lang="en" data-n-head="...">
<head>...nuxt generated head...</head>
<script>
// this tag needs to exist as html when building with 'yarn generate'
// ##config## is a macro
let config = JSON.parse(decodeURIComponent(escape(window.atob('##config##'))));
</script>
<body>
... nuxt generated body ...
</body>
In essence, when I run the command yarn generate I would like a specific page (pages/login/index.html) to have this specific tag to exist and not injected during vue's lifecycle. There are alternate solutions like having scripts automatically postprocessing the static page output, but I'm hoping that there is a way to accomplish this without such complications.
My nuxt version is 2.15.8
I am working in react js. I put all the assets links in public/index.html. When i start project, only first page works fine. When i navigate to other pages, all pages does not show the correct resul, and when i get back to first page it does not work. I checked the css and javascript files by ctrl+u. All files are loaded. The Both source files, before navigate and after navigate are same all files are loaded but on navigation it does not work. Please have a look on my index.html, how i use link tag to import css and javascript file. Any help would be appreciated.
Thank
I put all links to app.js and assets moved to src directory. Css files are working but jquery shows following error
import your CSS file in the "App.js" file. It'll work
I am building an Angular4 WebApp using an external HTML template for my components. The template needs to run some scripts to load correctly the page.
If I include script tags in my index.html the page loads fine the first time but when I route to another page scripts are not reloaded for the component template and the page remains blank.
Is there another way to load scripts and solve this issue?
Please Help.
here are my files. when application loads it works fine but when i route to some other page the js links in index.html wont load.
My app.component.html file only have
this is my app.module file
index.html
I'm new to JS development, basically from PHP Background. I was wondering if there is a way of including html pages like we do in codeigniter(loading views). Im trying to create a template structure to my electron application where header and footer file is loaded on every html page requested.
I cant try the jQuery load method
$('#footer').load('header.html');
as I would need to load jquery in footer of every file html file I create.
I tried the JS way of loading html files
document.getElementById("head").innerHTML='<object type="text/html" data="header.html" ></object>';
but that basically creates an object which is similar to an iframe so your resources never gets used to the way you would load using link and script tags.
I have a main.js file from where the home page would be loaded:
function createWindow () {
// Create the browser window.
mainWindow = new BrowserWindow({width: 1280, height: 742, resizable:false})
// and load the index.html of the app.
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, 'app/views/index.html'),
protocol: 'file:',
slashes: true
}));
}
How do i attach the header and footer directly in this method? Also I'm using express if that helps.
Please see this plunker for an angular 1.5 example, or check the documentation. Basically you want to do this <div ng-include="'yourtemplate.html'"></div> for the angular setup.
For EJS templates, you would do something like <% include includes/header.ejs %>
I would wrap those in the bootstrap navbar-header class and footer tags for optimal placement, or any custom div that you are working on.
Now, when it comes to using these in Electron, I would incorporate these files into your 'main' browserWindow, so that when the application runs, the index.html file you are referencing always has these files loaded.
Another thing you can do is use ng-if statements to change the ng-includes based on certain parameters. The same can be said with any server side template like EJS.
I'm a AngularJS-Beginner and i've just started using ng-include to better structure my html blocks.
I'm using jquery.scrollTo.js to add a button to scroll to the top. However i've noticed that if I place the button inside tpl-footer.html and load it via ng-inlcude while having jquery.scrollTo loaded in index.html, it won't work.
I either have to place the button inside index.html or load jquery.scrollTo.js inside tpl-footer.html.
My question: How can I access loaded scripts in index.html via ng-included templates?
Cheers!