Browser Print a custom html in React js - javascript

I am getting a HTML div from an API response and I want to send that response to the browser print command at a click of a button. Usually, window.print() works if you want to print the current page. But my current page has a different UI and the page I want to print is different. Any suggestion on how we can do this in React js?
Changing the current page and calling window.print() doesn't look like a feasible solution. The UI doesn't look that way. Any other solution appreciated. Thank you.

You might consider a package like https://www.npmjs.com/package/react-to-print
or check out this existing answer:
How to print React component on click of a button?

Related

Python requests: post JavaScript commands

I'm trying to get the content of a site, but this content only appears when I click the 'Chart' link, which is a JavaScript command like this:
javascript:__doPostBack('fcc1$dgrC$ctl02$ctl00',''
from a element like this:
Chart
This is the site:
And this is what happens when you click on 'Chart':
You can see that the link doesn't change, so the only way to get the chart code is by somehow send that JavaScript command
How to find all the chart links?
How can I do a 'virtual click' on the chart links?
And after that, how to get the new html?
I really appreciate your help!
doPostBack just sets the __EVENTTARGET and __EVENTARGUMENT form fields and submits the form. Those ''s are just quotes BTW.
If those links are indeed "clicked" by javascript listeners, you may have trouble finding a real link to click.
Instead, you could use a tool to simulate a web browser in python and "click" on that link to get to the next page. The best one I've used is Mechanical Soup: https://mechanicalsoup.readthedocs.io/en/stable/introduction.html.

Fetching Dynamic Website Data Using Java

I am currently using Java (Eclipse) to build this application which will be able to take a spans value from a specific website and show those values on console. But the issue i am having is, the Website i believe is Dynamic and therefore, i am not able to get those span values. The span (id=spot) keeps refreshing every 1 second and i guess it uses JavaScript. The class keeps auto changing as well when i do a "Inspect element". But if i do "View page source", there is no value inside the span. Could anyone suggest anyway to either render the web page and fetch data or any other method to do this. I have been
on google for the past 2 hours and nothing helped. I am new to this selenuim, JSoup, rhino which did not help at all. So please try to elaborate as much as you can :)
Here is the Web Page: https://www.binary.com/trading?l=EN
span id=spot

Keep most HTML after link clicked

Hi i want to make an effect similar to what this site does http://www.hffm.co.uk/
When you change the page the url up top changes but the content in the sidebar and header stays the same. - i am also curious if this affects SEO.
They stay the same - and do not reload with the page - i figure it has to be some ajax thing? Curious what a system like this is called.
The point is in their case they dont want to interrupt the radio on a link change.
To update the specific part of the page it can be achieved through Ajax and JQuery. Basically both of the those works on the client side which means that website doesn't refresh. You can always make a Ajax request to the server which can return the content in a Json format and that content can be reflected on the page using Jquery.
This is only just a overview of how ajax/Jquery works. But you need to be more specific in what you are trying to achieve and what you have done so far.

How to create an alert dialog with "more" or "details" expendable section?

I am interested in displaying an alert to a user with OK button to close the alert, and a more/details button which upon clicking on it displays certain details (text, table, data, etc). Can it be done using PHP/HTML alone?
The situation you're describing is possible, but would not be the accepted or fastest way of doing it. Using PHP requires a trip back to the server which reloads the page - not something you want to be doing if you want easy usability.
The recommended solution is to use Javascript, or jQuery. I would recommend against using jQuery UI unless you're going to use more than one part of it - it's a great library but it has much more functionality than you need and unless you host the file yourself, the download you get from major CDNs is large and will take a while to load.
However, there is a solution I know of and have use called Alertify. It is a JS plugin that deals specifically with alert, confirm and prompt dialog boxes, and can be fully customised. Here's the site if you want to have a look: https://fabien-d.github.io/alertify.js/. It comes with demos and example code so you can adapt that to your purposes.

Refreshing Javascript on the page without refreshing HTML

A little context on my problem.
I am updating the MathML in this div that is currently displaying HTML. When I load the page the first time, if runs the MathJax script and displays all the MathML perfectly.
When I click "Preview Changes", a button that takes the current changes made in a text area and displays them on the preview div, the MathML disappears.
I think problem here is that refreshing the div doesn't trigger the MathJax script. I have tried $.getScript(), and I tried adding a script using document.createElement(script) everytime the preview changes button is clicked, but all that to no avail.
I was hoping if someone could help me w/ this.
Thank you in advance.
MathJax.Hub.Typeset() is the JavaScript command that can re-render the math content within your page or within individual elements that have been updated by current changes. If you are sure that all typesetting is finished, then you can call it directly, but in general it is good to use the safe way to call it, like this MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
Read more instructions for how to use it here: http://docs.mathjax.org/en/v1.1-latest/typeset.html
For instance, MathJax.Hub.Queue(["Typeset",MathJax.Hub,"previewdiv"]); would re-render the updated contents of the HTML element with an ID of previewdiv after you have updated its contents using your jQuery call.

Categories