I have an invoice system made in PHP. There is a view with all customer's invoices. I'd like to make an option to print an invoice.
I know about window.print() and media="print" for CSS. But I was thinking, is it possible to just print an invoice by clicking a button next to it, but staying on the list page? It would just open a printing prompt with different content and do nothing to the current experience.
I thought of a workaround. On click, I could just replace contents of some element with invoice's data and make the styles hide everything else besides that container. That looks like a trick to me though. Is there any other solution to that problem? Perhaps something like download attribute for links:
Download Me
That could be something like:
<a href="invoice.php?id=3" print>Print Me</a>
Or perhaps an HTTP header? Please share some advices.
I would suggest to use JQuery PrintJS plugin below:
http://printjs.crabbly.com/
This will ultimately solve your problem.
Related
I'm using a plugin on my site to enable quiz functionality. When a lesson/quiz has been completed by a user there is a popup that features a button with a link back to another page. The problem I have is that I need to change this link.
This is what console looks like:
View Console
I need to be able to edit the href link shown here so that I can redirect users to the correct page. Firstly I need to know if this is possible and secondly how I could go about implementing this change.
I'm presuming it can be achieved with JS, but my knowledge of JS is limited so I'm unsure about the execution.
You can change attribute href as simple as any other attribute:
$('a.gdlr-lms-button').attr('href', 'new-url');
With jquery you can do it like this.
Where test the classname is so just replace that by gdlr-lms-button
$('a.test').attr('href', 'www.google.be');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a class='test' href="www.facebook.com">Hello</a>
I know there is plenty on the subject but not what exactly i want...
I've tried window.location.replace("http://gmail.com")but it replaces the content only in a specific <div> in the page instead of the whole page..
In the w3schools tutorials of location.replace for example
http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_loc_replace
It allows you to load the new URL in the box on the right of the page.
In my case, i want a javascript that will replace the whole page, and not only in the small box on the right.
I hope i was clear enough.
It sounds like you've got code in an <iframe>. If so, you can reload the whole browser window/tab with
window.top.location.replace("http://gmail.com");
I'm under a bit of a deadline so I was hoping that before I proceed down any paths someone could tell me if what I'm doing is feasable or if there is an easy/quick way to resolve it:
After running into some issues with an accordion menu I have opted for an interim fix of using several menus and replacing each of them with js. I don't have the code in from of me but essentially:
function change-menu(menu){
var new-menu = menu + ".php";
(#menu-area).load(new-menu);
}
(I've only done a little work with js so far so please ignore the above syntax... I'll try to fix it later.)
And my link would be something like:
<a onclick="change-menu('something')">Something</a>
Inside the side menu are thumbnails for the artwork that will load in the window area and to keep it simple I'm just using a php include that will look something like:
[img goes here]
But I realized that when I do that I should also pass the menu to the next page as well so it knows what menu to initially load in the new page. But then I though - and I'm overanalyzing this and bit - if I want the experience to be stremalined and look a certain way even if I'm coding it a bit bitmakeshift at the moment I dont want someone to hit the back button and have the menu start opening and closing different parts.
So the question is:
Is there a way that I can tell the php link to import whatever the current state/value of the sidebar? I just want to make sure that the side menu only changes when the user clicks on it and not from hitting the back or forward buttons. Is this an easy action? Is it even a possible action? Are there better solutions?
You should look into AJAX to achieve this. Using AJAX, you can get the new content as HTML from a php page and then use JavaScript to replace the existing content of the sidebar with the AJAX return. This way the content of the sidebar will be changed without reloading the page.
No you can't do it in php. Use Javascript instead.
i want to open html href link files in message box or any display box.( sorry i dont know, exact word for box.)
is there any way to open href links in any kind of display boxes.? i need answer only in JavaScript technology. Help me
I don't think an alert() or confirm() or any other built-in browser dialog box can display more than just simple text. But you can have any HTML content you want in a modal div dialog. The jQuery UI Dialog is a popular example. You don't need to use that plugin, though it would make it easy.
Essentially you just render a hidden element to the page (commonly a div) and respond to some page event by styling the element to "float" over the rest of the page. That element, since it's part of the DOM like anything else, can contain any HTML you'd like.
Take a look at jQuery's fancybox -> Fancy Box
well depending on how you building your web app. You could integrate twitter bootstrap, it has tons of great JavaScript plugins. a modal might solve your problem.
http://getbootstrap.com/2.3.2/javascript.html#modals
Alternative you can uses a lightbox, I see someone has already mentioned fancybox. The second version is now out.
its supports images, iframe, and divs as conetent
http://fancyapps.com/
I need to automate a process that involves getting data from a series of links on a website.
Greasemonkey could do the job, but I can't get the content from inside that link.
The link looks like this:
<a id="ctl00_main_gvPolite_ctl02_lbDetaliiPolita" title="Detalii polita" class="icon16 icon-detalii" href="javascript:__doPostBack('ctl00$main$gvPolite$ctl02$lbDetaliiPolita','')"></a>
This would be the important part: javascript:__doPostBack('ctl00$main$gvPolite$ctl02$lbDetaliiPolita','')
I can't find that function defined anywhere in the javascript, it's only used at various points.
A frame pops up over the website displaying the content I need. After I get it in a variable I can just send it to a script on my server for processing.
For anyone interested, I was missing an input called __VIEWSTATEENCRYPTED
It's further down the page in the source code, just include it in your $.post(); or whatever you use and it will work.
All credit goes to MaxArt for this one. Thank you!