I am working on a page which will have an area at the bottom listing out groupings of FAQs with a few different tab levels and then questions which can be expanded/collapsed by the user. We want to provide a way for the user to be able to nicely print
Just the questions/answers they have expanded
All the questions/answers in the sub-group they have selected
All the questions/answers in the primary group they have selected
All the questions/answers on the page
The plan is to have a drop down box with a print button (unhidden by Javascript) that would apply a class that when clicked that would hide the other content on the page and give us the display we want for the user selected option. This is all easy enough to do and we can apply a default print-style using #4 as a catch-all when javascript is disabled which can just be triggered via the normal print mechanism.
The problem is how to remove that special style when the printing is done so that if the user were to go and click the browsers print button, they get what they expect a print out of the whole page instead of the last selected "special" print view.
I have thought up a few potential solutions but I am not entirely happy with any of them:
We could replace our planned in page print with a link to another page which formats itself without interfering with the rest of the page content. I don't like this idea because it breaks the page into pieces and if possible I always prefer to keep the user on the page.
We could set a timeout when the print button is clicked to remove our special class after some period of time bringing the page back to a default state. I don't like this because it will produce unpredictable behavior from the user's point of view. If they take "too long" printing the first time they don't get the style they want. If they print the whole page "too quickly" after the special print they get an odd result
We can use the after-print trigger in IE to remove the style for those users, but as far as I can tell this sollution is only an option in IE and leaves all the other browsers in the cold.
We could make a general assumption that a user is very unlikely to come to the page and do a special formatted print followed by a desire to print the entire page and just let is go at that.
Any other solutions anyone can think of?
Your first solution is actually very good if you use target="_blank". This would keep the user on the page but avoid all the other problems.
However, I think the whole problem is moot if you make the page layout match the dropdown. In other words, if they're looking at Section 2, Subsection 3, Question 1, and they select
"print all questions in subsection", just expand the subsection and open the print dialog box. Then you only have to worry about setting a single class (noprint) and apply it to everything else.
Related
I have designed a page to be used as a tool. I am getting some challenges here since my experience is very little in the field and im only new.
- my goal is to change values of an element on a page that is not open yet.
- is there a function i can make on current page to change the values of the element on the next page to preset it to some static numbers or some of them are dynamic
I dont know how to manipulate something that is not open yet, i dont even know if that's something possible. I was able to change elements on my open current page, but dont know how to change something on the next page if i click on one of the links
Park Property Management
Millgate Manor
Weston Towers
Kingston
Region Of Peel
so i expect to click on one of the links and when the link opens some elements in the links i need them to be filled with some values that are static always
You can't directly influence the content of another page with JavaScript in the current page. That would have very big security concerns.
However, you could indirectly influence the content if you have access to the source for both pages, and can add JavaScript to both of them. Then, as some comments suggested, you can for example use search paramaters in the link url to pass along information.
(Search parameters are the stuff that comes at the end of a url sometimes and looks something like ?name=john&id=555)
You can read more about about working with search parameters in JavaScript here:
https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams
Don't get discouraged! You're capabilities will grow as you try to make things work. (That's almost the only time they will grow.)
A word of caution!
Please be very careful when using search parameters to modify or display content on a page as there are some real security concerns involved. Never display anything from the search parameters directly on the page without validating the input first. A good way to handle dynamic content based on search parameters, at least if you know the possible options available, is to have some if .. else statements or maybe a switch block that you try to match the search parameters against, and simply not display anything at all if the content of the parameter does not match any input that you're expecting.
I have been trying to highlighting multiple search result hits in the textareas - multiple textareas - of a form.
After much searching and many trials I found a solution while I was preparing this question for S.O. but before I submitted it. I thought it worth recording here to save time for anyone else with the same problem. I hope this is an acceptable thing to do on S.O. If not, moderators, please delete.
In the app I'm working on, users enter text and it is stored in MySQL where each record corresponds to a form. Users can recall any record for editing, and when they do, they will be presented with the previously-entered data in text areas again to modify. This all works.
Now, I've implemented a search function to search the whole table, and when the user recalls a record, I want to present it in the form for editing, with any and all search hits on a page highlighted - e.g. like this:
(source: informationtamers.com)
That's simplified, the actual form is longer, so the user may not notice other hits on the page.
I've made it work with a highlight for the first occurrence of the hit string if it's present in the form, but the problem comes when the string appears multiple times in one text area, or in multiple text areas on the same form.
I have tried these approaches:
setSelectionRange: This is the only one that even half-way works, but highlights only one string per form. This makes sense because AFAIK you can't have more than one item selected in an html input field or form and as a UI for someone looking for the results of a search it's not very user-friendly.
add style at the appropriate points in the input text: <span style="background-color: yellow">ZZZZ</span>
I didn't expect this to work, as it's input in textarea, but I did try it and it just shows the html. (For the record, the user's data is escaped immediately it's submitted.)
Invoke the browser's own search facility and pass it the search term. I failed to find any way of doing this on three counts: I can't find a way to trigger Ctrl+f programatically, inject the search term into the browser's search box and initiate the browser search programatically.
Johann Burkard's 'highlight' jQuery plugin. http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html
This is capable of highlighting multiple entries on a page, but not in textarea fields, which as far as I can see it ignores. I believe I've set it up and invoked it correctly, because I can get it to highlight multiple text area captions on the page. It works by adding <span class="highlight">Search result</span>.
This http://frightanic.com/projects/jquery-highlight/ from frightanic gives results the same as Burkard's plugin.
This http://www.jquery.info/The-plugin-SearchHighlight from Renato is targeted at search engine results, so is not my use case.
This http://jaspreetchahal.org/examples/jquery-onpage-text-highlighter-and-filter.html filters out paragraphs that don't contain a matching string so I didn't try it, but the demo shows that it uses <span style="background:yellow;color:#000000">Search result</span> to highlight, like the others, so I doubt it would work on text areas.
The one that, after some playing around, did what I wanted: http://bebo.minka.name/k2work/libs.js/jquery/2.1.0/highlightTextarea/
Some points to note.
The text areas must not be resizable. The documentation says this, but also documents an option 'resizable' and says that the jQueryUI Resizable is required. I tried this and it did not work. I guess it was an intention but was not debugged, as the author says he's no longer working on the plugin.
I'm using this with colorbox, and found I had to .highlightTextarea("destroy") and then .highlightTextarea("disable") when user leaves the form, or the highlights appeared when viewing records that had no hits.
In some circumstances, the CSS conflicted with mine and messed the form up, so when the user cancels the search, I .remove the form from the DOM and rebuild it. This is probably due to the way I'm using the plugin, and not the best solution, but I couldn't find how else to resolve it.
The result now seems to be solid, and provides the effect I was trying to find for so long.
I need to sort messages, and I can either remove them or approve them (or ignore).
I want to create a script (probably using Tampermonkey - I'm using Chrome on mac) where I could input a list of recurring words (swear words I would input) for which it removes the messages so that it can go faster, it would automatically click the remove button after if it find the word(s) in the message.
If it doesn't find anything I want it to do NOTHING, just leave the page as is.
Basically usually after I click the button the page loads again automatically and gives me the next message.
I don't really know programming, I'm mostly just around html/css and a bit of jquery, but I'm learning here and there.
How can I achieve this ?
Thank you very much.
I'm pretty sure I can't do what I'm actually asking, but am wondering if there is some sort of workaround for the issue.
I have a page that has a drop down SELECT form element with several options. If one particular option (in this case, the first item) is selected, we show additional content (via jQuery). This works fine.
What happens, though, is that if I select item 2, the additional content disappears, as it should. I then go to a different page and then hit BACK. A that point, the page properly has kept that additional content hidden (as it was the last state) but the SELECT menu has been reset to the first item. I then have to click the SELECT, pick a different option, then select it again picking the first option, which finally brings the additional content back.
I can't trigger Javascript from what I can tell on a cached page (or is there a way?) Any other clever options?
One option I've come up with is to apply some sort of mouseover action to the area that houses the SELECT menu that does a quick 'reset elements' check. This seems a bit hacky and, of course, will produce an odd screen redraw unexpectedly for people.
You can record that the user action has taken place and re-execute it using JavaScript. You can store it in a cookie, then check for it on page load and reset the elements you want.
No thoughts on this one? Anyone?
Here is my scenario:
I have a form where the user selects a report type, and then selects a list of users they want to generate reports for. When they submit the form, a new window is opened that uses pagination to allow the user to review each user report individual by using next and previous links.
The user wants the option to:
print both the currently displayed report by itself (that's an easy one), and
a "print all" option to print all the selected reports.
However, each report for each user must have its own "Page x of n" footer.
For the footer, I have been using the browser footer options, but in order to have the page numbering start new on each report printout, I have to make a separate window.print() call for each one. I have implemented this this way, and it works, but it's awful because each print() call causes a new print dialog to display, meaning the user has to click print in each dialog to finalise the print request. Many reports = a stupid number of popped up print dialogs.
Ideally, I would like the printing of a report group to look like a single print job, but I need that page count to be restarted for each report.
I thought of trying to count pages myself to make my own footer, but that seemed like a daunting task considering all the variables that could affect how many pages a report would occupy. I also read some about using ActiveX and WebBrowser objects to force prints and hide the print dialog, but I have had no success with that because I am running on XP SP2. Also, I understand it's frowned upon from a security perspective, and it's not a good cross-browser solution.
Has anyone dealt with printing of this type before and would have some suggestions for a way to make this work or a better way to handle it?
Thanks in advance.
I've seen this done two ways the simplist using the MeadCo scriptx component which alows you to print without a dialog. But as you rightly say this is not good from a security perspective. This was done in a corporate environment where they had control over the end users browser.
The second would be to go down the ajax route and load each report page individually, without prining, then concat each report html together into one doucment adding any needed page breaks. Finally rendering to an IFRAME and calling print on that frame to print all reports in one action.
This isn't tremendously helpful, but you may want to look into using a pdf generator, such as PDFlib or fpdf. Doing this with static pages will incur all the problems you stated, as well as some which you didn't (such as the user setting his own font or font size and ruining your pagination).