How to set the number of copies to print from javascript [duplicate] - javascript

This question already has an answer here:
javascript window.print(), passing number of copies as param
(1 answer)
Closed 7 years ago.
I am trying to print a document using print method of javascript.
Now i want to set number of copies to print(by default it will print 1 copy).i want to set the number of copies to two(2 copies).
Is it possible to do it from js code.We can set by printer settings,but it will print for all the copies.I need it for specific document to print 2 copies.
My code is :
$scope.printPDF = function (id) {
window.frames["doc1"].focus();
window.frames["doc1"].print();
window.frames["doc2"].focus();
window.frames["doc2"].print();
window.frames["doc3"].focus();
window.frames["doc3"].print();
};
Now i want to print doc2("only doc2") as 2 copies.remaining should be default 1 copy.
Thanks in advance.

There are no additional parameters for the window.print() method and definitely no parameter that allows you to specify the default number of copies.
The only workaround for this that I can think of would be to call the print() method twice on doc2. Obviously not the greatest user experience.

It is not possible, one solution would be to call the print twice
window.frames["doc1"].focus();
window.frames["doc1"].print();
window.frames["doc1"].focus();
window.frames["doc1"].print();

Related

How to extract a large type with vs-code without the '... 19 more ...' truncate? [duplicate]

This question already has answers here:
How to see a fully-expanded TypeScript type without "N more" and "..."?
(3 answers)
Closed 8 months ago.
I have a large object (pvtMsg). vs-code shows a popup with the type when you hover over it. I would like to copy the entire type and paste it in another file. Then I would import that file in places where I want to use that type.
The text is selectable, but the type is not complete, when I copy the text with ctrl + a the text ... 19 more ... is copied. Is there a setting in vs-code to increase the maximum length before truncation?
This issue also occures with javascript or .js files.
It might sound unintuitive, but the noErrorTruncation compiler option does not only control error messages, but also toggles truncation of type hints. If you set it to true in your tsconfig.json (or pass the equivalent CLI option), you will notice that the hints are no longer truncated.
For example, let's make an object Test with 35 properties. Here's how the hint looks like with noErrorTruncation: false:
And here is how it looks like with noErrorTruncation: true:
Playground
Note that there is a hard-coded absoluteMaximumLength cutoff (calculated from defaultMaximumTruncationLength to a total of 1600 chars ATTOW) at which point the display will be truncated regardless of whether the option is enabled or not.

updating global variables javascript/html [duplicate]

This question already has answers here:
Persist variables between page loads
(4 answers)
Closed 7 years ago.
so currently I am building a website where I get data from google spreadsheets and then graph it on my website...
However, because this data is constantly streamed from somewhere else, I need to be able to show 10 data points on the graph every time. (So shows 10 data points then the next 10 and then the next 10 and so on). So I personally need 2 global variables to keep track of where in the data I am thus be able to present the user with the correct graph.
I have tried this...
<script>
var i = 0;
var lengtharray = 0; //This variable is the second global variable that I need and is updated within the same function as i.
function doSomething(){
anotherFunction();
i = i + 10;
lengtharray++;
}
</script>
so the next time the script is run to show the next data point on the graph, the i value that I expect is the previous i value + 10 and the lengtharray value to be incremented...
instead, what I get is i = 0 again and lengtharray = 0 again..
I need these values to be "updated" and only initialised/reset when I want it to be/the browser closed and reopened on the webpage...
I hope this question all makes sense!
Thanks in advance.
If the problem is due to those globals and the function being re-instantiated every time then you might just be able to use a singleton pattern to prevent this. If you are unfamiliar, it is a design pattern that always returns the previous instance of your class, variable, whatever. That way there is always only one instance of your object, class, variables etc. I have linked the implementation in javascript here

How to pass parameter value of server-side method from JavaScript? [duplicate]

This question already has answers here:
How to pass a javascript variable to server side method
(3 answers)
Closed 7 years ago.
Here is an example:
JavaScript:
var b = 'Banana';
var list= <%= getJson() %>; // want to pass b?
C# Method:
using System.Web.Script.Serialization;
....
public string getJson(string x)
{
var list = new List<object>{new []{ "1","Apple"}, new []{ "2",x}};
return (new JavaScriptSerializer()).Serialize(list);
}
How can I pass variable b when I call getJson() from JavaScript?
The problem is, the server-side code executes and generates the page (including the javascript which is just text at this point). The page is then sent to the browser where the javascript is executed.
By that time, it's too late to do anything server-side.
Your options are:
Do a GET/POST/similar of the whole page back to the server, with the new variable from JS in a form field. This is trivial but causes a full-page refresh and is becoming less and less desirable.
Use a Javascript Ajax request to pass the variable back to the server and ask it for updated content. Use the response from the server to update the page for the user
The documentation for how to do the latter using jQuery is available here and there are literally thousands of examples around Stack Overflow.
Remember, anything called inside the <% ... %> tags get processed on the server side before the page even loads. If you need to dynamically load information from the server based on a variable, you need to make an AJAX request.
If you are able to, the easiest way to do this is with jQuery.

How to check for a substring in JavaScript? [duplicate]

This question already has answers here:
How to check whether a string contains a substring in JavaScript?
(3 answers)
Closed 8 years ago.
(Because a (Define) My php file shows a second line). It will have like OK+a empty line
So I would like to make my check so it's like not if responde = OK
but if response contains OK
Full code: http://meepbeta.tk/hotel/minified.js
The line I'm talking about:
var b=d.responseText;if(b=="OK"){saved=true;if(!a){var a="http://sunniedaynl.net/client"}showResult('<img src="dissi-editor.png" style="float: left;padding-left: 25px;"><strong>
Won't work:
Is there any way to make it like
if(b.Contains("OK")) //<--- This doesnt work
It doesn't work because of the second line
This is the script it checks:
function sendMap(){var a=getExport();asyncAjax("POST","check.php","gamemap="+a+"&doorx="+doorX+"&doory=‌​"+doorY,doChecks,{}
Then, it checks for the OK
b=d.responseText;if(b=="OK"){saved=true;if(!a){var a="sunniedaynl.net/client";}showResult('<img src="dissi-edit
But I want it to check for something that contains OK not just check if the whole text is OK, so it'd even detect it if it was like OKay32r34.
I'd go with b.indexOf("OK") === 0. This ensures that the first two characters of b are "OK", matching "OKay32r34" but not matching "rOK".
I'd also like to note that b.Contains doesn't work because there's no method Contains defined, there is however contains but it checks for it anywhere in the string. (and thus would match "NOT OK")

Replace multiple string instances in javascript [duplicate]

This question already has answers here:
How do I replace all occurrences of "/" in a string with "_" in JavaScript?
(4 answers)
Closed 8 years ago.
String contents :
background:url(abcd.gif); background:url(images/header2.gif) no-repeat;
background:url(images/bullet1.gif) no-repeat 11px 13px;
Javascript Code :
var testRE = originalcode.match("url\(\(.*)\)");
testRE = testRE[2].replace('(','');
testRE = testRE.split(')')[0];
var img_path = "http://xyz.com/800002418/"+testRE;
originalcode = originalcode.replace(testRE,img_path);
In the above code it's only replacing first instance of match. I am trying to replace multiple instances for url in string like above are 3 instances in string for url. But it's only replacing 1st instance and that is "abcd.gif" to "http://xyz.com/800002418/abcd.gif". And rest is as it is.
I suspect what you're actually trying to do here is as follows:
originalcode = originalcode.replace(/url\(([^\)]*)\)/g, "url(http://xyz.com/800002418/$1)");
See #Phylogenesis's answer for how to do what you seem to think you want to do, but is that what you really want to do? After you've modified the string, what are you going to do with it? I suppose perhaps you're going to set it as the string CSS value on some element, as in elt.cssText=. But why do you think three background properties in a row are going to do anything useful? Each one will just override the previous one.
Taking a step back, instead of trying to manipulate CSS declarations as strings using regexp's, I suggest manipulating individual property values. So, something like
foo.style.backgroundImage=foo.style.backgroundImage
.replace(/\(.*)\)/,"http://..."+$1);
But I'm still confused as to why you would want to do this. I guess it's because the remote URL is only known at run-time? The most flexible solution is to place a CSS file on the host in question and load it. If the images are there, you ought to be able to arrange to put a CSS file there along with them. The URL references in the background property values will then automatically be interpreted in terms of the URL of the CSS file, without having to rewrite in this ugly fashion.

Categories

Resources