将打印机名称与 javascript 连接时出错
error when concatenating printer name with javascript
它是关于查找系统已安装的打印机,但是当找到它们时,JavaScript 代码在 "brand" 之间的空白 space 中连接了一个 % 20(Zebra ) 和 "model" (GC420t) ...我附上一张图片
问题是当我将此参数传递给函数 PrintCommands 时无法识别打印机...真相....在组合中它正确显示了打印机的名称..
我的看法:
<h3>Impresión de Etiquetas</h3>
<div>
<label class="checkbox">
<input type="checkbox" id="useDefaultPrinter" /> <strong>Usar impresora por defecto</strong> o...
</label>
</div>
<div id="loadPrinters">
Click para buscar impresoras instaladas...
<br />
<input type="button" onclick="javascript:jsWebClientPrint.getPrinters();" value="Load installed printers..." />
<br /><br />
</div>
<div id="installedPrinters" style="visibility:hidden">
<label for="installedPrinterName">Select an installed Printer:</label>
<select name="installedPrinterName" id="installedPrinterName"></select>
</div>
<script type="text/javascript">
var wcppGetPrintersTimeout_ms = 10000; //10 sec
var wcppGetPrintersTimeoutStep_ms = 500; //0.5 sec
function wcpGetPrintersOnSuccess() {
// Display client installed printers
if (arguments[0].length > 0) {
var p = arguments[0].split("|");
var options = '';
for (var i = 0; i < p.length; i++) {
options += '<option>' + p[i] + '</option>';
}
$('#installedPrinters').css('visibility', 'visible');
$('#installedPrinterName').html(options);
$('#installedPrinterName').focus();
$('#loadPrinters').hide();
} else {
alert("No printers are installed in your system.");
}
}
function wcpGetPrintersOnFailure() {
// Do something if printers cannot be got from the client
alert("No printers are installed in your system.");
}
</script>
<br />
<input type="button" style="font-size:18px" onclick="javascript:jsWebClientPrint.print('useDefaultPrinter=' + $('#useDefaultPrinter').attr('checked') + '&printerName=' + $('#installedPrinterName').val());" value="Print ZPL..." />
@section scripts{
@* Register the WebClientPrint script code generated by PrintZPLController. *@
@Html.Raw(ViewBag.WCPScript);
}
我不明白“% 20”如何与品牌和型号之间的 space 联系起来....对我有什么帮助吗?
pd:当传递名称时不带“%20”作为参数,脚本可以正常工作
您的后端代码中需要某种 URL-decode 函数。我不太了解 C#,但我认为你会这样做:
printerName = HttpUtility.UrlDecode(printerName);
...在 PrintCommands() 的开头。
它是关于查找系统已安装的打印机,但是当找到它们时,JavaScript 代码在 "brand" 之间的空白 space 中连接了一个 % 20(Zebra ) 和 "model" (GC420t) ...我附上一张图片
问题是当我将此参数传递给函数 PrintCommands 时无法识别打印机...真相....在组合中它正确显示了打印机的名称..
我的看法:
<h3>Impresión de Etiquetas</h3>
<div>
<label class="checkbox">
<input type="checkbox" id="useDefaultPrinter" /> <strong>Usar impresora por defecto</strong> o...
</label>
</div>
<div id="loadPrinters">
Click para buscar impresoras instaladas...
<br />
<input type="button" onclick="javascript:jsWebClientPrint.getPrinters();" value="Load installed printers..." />
<br /><br />
</div>
<div id="installedPrinters" style="visibility:hidden">
<label for="installedPrinterName">Select an installed Printer:</label>
<select name="installedPrinterName" id="installedPrinterName"></select>
</div>
<script type="text/javascript">
var wcppGetPrintersTimeout_ms = 10000; //10 sec
var wcppGetPrintersTimeoutStep_ms = 500; //0.5 sec
function wcpGetPrintersOnSuccess() {
// Display client installed printers
if (arguments[0].length > 0) {
var p = arguments[0].split("|");
var options = '';
for (var i = 0; i < p.length; i++) {
options += '<option>' + p[i] + '</option>';
}
$('#installedPrinters').css('visibility', 'visible');
$('#installedPrinterName').html(options);
$('#installedPrinterName').focus();
$('#loadPrinters').hide();
} else {
alert("No printers are installed in your system.");
}
}
function wcpGetPrintersOnFailure() {
// Do something if printers cannot be got from the client
alert("No printers are installed in your system.");
}
</script>
<br />
<input type="button" style="font-size:18px" onclick="javascript:jsWebClientPrint.print('useDefaultPrinter=' + $('#useDefaultPrinter').attr('checked') + '&printerName=' + $('#installedPrinterName').val());" value="Print ZPL..." />
@section scripts{
@* Register the WebClientPrint script code generated by PrintZPLController. *@
@Html.Raw(ViewBag.WCPScript);
}
我不明白“% 20”如何与品牌和型号之间的 space 联系起来....对我有什么帮助吗?
pd:当传递名称时不带“%20”作为参数,脚本可以正常工作
您的后端代码中需要某种 URL-decode 函数。我不太了解 C#,但我认为你会这样做:
printerName = HttpUtility.UrlDecode(printerName);
...在 PrintCommands() 的开头。