webshot of another page on localhost-Meteor - javascript

I am trying to figure a way to render a webshot view of another page in my project without actually having to visit said page. The end goal should be taking a webshot of the page and returning it as a pdf to the client. Currently I have a view button, which will dynamically render a styled HTML page with relevant data in a new window at a specified URL(this is what needs to become a pdf).
Using webshot, would I be able to just specify the URL that renders the page and then take a webshot? Or will i have to look at using SSR methods to render the page on server side and webshot that result?
when I do the webshot of the URL that should render the page, All that is returned is a blank PDF. Is webshot even possible to use on localhost pages? If I were to webshot "www.google.com" I am returned a view of google.com, so the webshot code works, just not at the local URL I need. Where am i going wrong? I am new to using webshot.
Thank you

Related

How to render a page then download it in express js

I want to render a page (output.ejs) and then download that same page all with one button click. In my POST method I redirect to "/output" where the GET request renders output.ejs. However I cannot call res.download("") after that render (something to do with it being asynchronous). What's the best way at tackling this. BTW I am using wkhtmltopdf as PDF generation which needs to happen AFTER the page gets rendered since I am sending data to it.
Best
Try res.render('/output').download()

Integrating HotJar in SPA with same URL

I'm trying to integrate Hotjar with an admin panel.
The way it currently works is some sort of SPA without page loads and neither URL changes.
It all happens under /index.php and then when we need to change a page, just send an AJAX request to load it's content.
From checking the documentation, Hotjar seems compatible with SPA's but only when there's a change in the URL (either query string or hash).
Is there a way to trigger in JS a page change to a page name (i.e. Main Page) ?
I've tried
hj('vpv', 'Main Page')
But the output seems weird
url: "http://mydomain.comTest Page"
Thanks.
You can track your changes manually by adding additional JavaScript after your AJAX calls.
Documentation:
To Manually Issue a State Change
hj('stateChange', 'some/relative/path');
Example:
Imaging that you have a SPA with base URL http://example.com/ and you want to track the main page and a page that gets dynamically loaded with AJAX once you click some button.
In order to do that, you would need to:
1) In your Hotjar account, create two heatmaps. For the main page, you can use the base URL http://example.com/. For the page that is going to be loaded dynamically, you can put a virtual URL, e.g. http://example.com/my-dynamic-page, which will be used only for recording and will not need to exist in your SPA.
2) In the JavaScript of your application, add the state change code after the AJAX call that will dynamically load the page.
You need to use the virtual URL that you defined in the previous step to let Hotjar know that this is a new page and you want to track it separately:
hj('stateChange', 'http://example.com/my-dynamic-page');

Generate pages based on url using Javascript in asp.net

At the moment I can generate pages by drawing the content with javascript based on ajax requests for JSON files which describe what is to be drawn.
The result is good, but I want users to be able to access a page such as www.example.com/SomePage where I use SomePage in javascript to display the content based on it.
Since SomePage isn't an actual existing .aspx page I get 404 error from the server. Could I capture the url path and hand it somehow to the javascript to generate the page dynamically? Thanks in advance!
You look for the HttpContext.RewritePath Method.
In a short, you read your path eg: www.example.com/SomePage
and using the HttpContext.RewritePath you translated it to
www.example.com/editor.aspx?id=SomePage
and there you have your SomePage value to use
on your javascript code
and still the url show www.example.com/SomePage

How to work request.render in node js

I am using GET and POST methods for getting data from the server and getting response using request.send(object);.
However my requirements changed, I need to use request.render('pageName',object); but the render method refreshes my page but I only want to refresh a particular <div> section. I read on this link https://www.npmjs.com/package/ejs but I am not able to refresh only particular section without refreshing the entire page.
If you want to redraw only a part of the page then you probably need some kind of client-side rendering for your templates. You fetch the data from the server using GET just like you mentioned and then do the actual drawing of the page on the client instead of sending HTML with request.render.

Calling router from backbonejs and nodejs

I have an web app. Basically its a single page application. The initial page is a flat html file called index.html, with a single script declaration pointing to require.js. From there I use backbonejs to handle the client side logic. The index.html is being served by nodejs.
My issue is that, any action within the page, for example, i click on a link, the backbone router is called. Which is the behavior I want being a single page application.
For example: www.testserver.com then i click on a link which shows a modal screen for registration www.testserver.com/register, via backbone router with push state on
The issue arrises when, instead of accessing a certain link within the app, i open the url straight in browser. For example I paste, www.testserver.com/register, in the browser. The request is then sent to my node router. I am assuming this is the correct behavior, since the page doesnt exist yet, meaning the backbone router doesnt exist as well.
I was wondering, on what the correct work around for this is. What am i supposed to do, when i access this link? How do i pass the correct behavior back to my backbone application.
Thank you very much.
The server should return always the index.html page. When you start the router in your Backbone than, the router handle the navigation and call the function you defined for the actual route.
Assuming you don't need to do any SEO type stuff such that each unique URL loads its own metadata, just always serve the same index.html as stated. However if you want to have different static head content based on the URL, you should do that within node based on the path (e.g. keep an array of metadata for each route that you slip into a slightly-more-dynamic initial view template, based on your existing flat index.html)

Categories