Multiple printing with Javascript [duplicate] - javascript

Is there any way that I can pass parameter value to javascript window.print() function. Suppose I would like to print 2 copies, but by default print dialog box shows 1.
Is there alternative function to call print and pass number of copies from browser?

No, (un-)fortunately that's not possible.
I'd say this is a good thing; otherwise some sites would specify a high number and people who don't expect this would accidentally print lots of pages instead of just a single one.

Related

is there a way to change elements of a page before opening it

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.

Saving value from page 1 to page 2 - uiWebView

Looking for a way to pass my 2 values from box 1 and 2 on page 1 to value box 1 and 2 on page 2 so i want to move the value between pages.
Hard part i'm using it in a offline Ios uiWebView and i cant get it to work, with local value storage or something similar.
I'm working inside a html page.
Thanks in advance.
EDIT:
It looks like you can use localstorage in the uiwebview the same way as you can in other full browsers (Which is what Joran ended up finding to work).
But you could also use the following if you want access to the variables in objective-c.
ORIGINAL:
Try using an Objective-c Javascript Bridge (Apple Docs). It allows you to essentially pass values back and forth between your objective-c code and the javascript page (Just like it sounds haha).
So you could store the values in an objective c NSMutableDictionary and pass them on to the next page when it changes.
My problem was simply solved by using LocalStorage in javascript to save the value this surprisingly worked.
Thanks for the help #SnoApps

Prevent line breaks in "alert" prompt in javascript

I know how to insert line breaks in a JavaScript alert (using '\n'), but how do I prevent them - that is, make the text remain on the same line within the alert.
I have a message I want to display that breaks on the last word of the sentence, leaving a very awkward looking message. So, for example, instead of this:
Please ensure proper text is entered into the form
The users sees this:
Please ensure proper text is entered into the
form
...quite unappealing.
I know I could alter the message to possibly make it shorter, but for future reference, I thought I would ask the question.
This isn't possible, because the styling of the alert dialog that appears depends completely on the browser's implementation. Different screen sizes and different browsers will enforce different maximum / minimum widths on these dialogs. Even shortening your text won't guarantee that it is restricted to one line on all browsers.
Your best solution would be to implement a JavaScript dialog of your own.
Javascript alerts are not customisable in this fashion because they are completely dependent on the browser itself. Consider using an in-DOM modal.
Unfortunately, there is no way to make the "alert" window wider, which means text that doesn't fit will wrap to the next line. I would suggest displaying the message in HTML instead.

Dynamically change a value on a asp.net page without actually refreshing it

I have a label, let's call it LblA. I have a SqlDataSource, let's call it sds. Now, I have selected out and managed to get specific values using the select function. I want to set LblA's text to the value selected out of sds. I need this to occur every 5 (or as many as I specify really) seconds. I orignally used a timer object, however, for any of you who have used the timer object before, it likes to refresh the page, this makes it very hard to navigate off of the page; not only that, it's sloppy. Does anybody know a way to easilly update LblA's text from sds without refreshing the actual page.
I've read around and came to the conclusion that I need to use ajax, err... jQuery. However, I really don't know anything about the two except that they are both Javascript libraries? I need a simple way, you might even have to explain it to me like I'm an idiot.
I'm using VB.net and ASP.net just so you know.
Thanks so much!
If you want it simple use UpdatePanel If you want more control and efficiency, use jQuery's Content

alert() prompt - Checkboxes

With alerts you can have text inputs. I was hoping you could put check boxes in. Is this possible?
http://www.w3schools.com/JS/js_popup.asp
No, you would need to build out a dialog box in order to achieve this.
You are able to achieve this with relative ease through jQuery and more specifically the jQuery UI plugin, allowing dialog boxes to come up without too much know-how
No. The only options are:
alert (display string);
confirm (display string and get yes/no|true/false back);
prompt (display string and get input string back)
You can create your own modal dialog using a variety of techniques. Under the hood, they all essentially do the same thing - display a separate web page in a popup window or iFrame and disable input access to the rest of the browser until the popup is closed. These are pretty easy to get wrong (hard to use + very annoying) but when done right they offer the developer a lot of power - since it's a complete web page you control, you can pass complex JavaScript objects between the dialog and the main browser window, instead of having to rely on the primitive interaction modes offered by the out-of-the-box dialogs.
Pretty shure it isn't possible. However, you can simulate a "alert box" with the contents you need. JQuery, for example, is a great javascript framework to achieve that.
no, but you can create a function that opens a alert box with html in it, like on facebook.
No, but you can create functions with alert boxes.
javascript:alert("Hello");
javascript:confirm("Hello");
javascript:prompt("Hello");
are the inly available ones.

Categories

Resources