我正在使用收据打印机打印到期标签。它使用触摸屏按钮组来打开打印窗口以将文档发送到打印机。在打印窗口中,我需要使用Javascript来编写产品名称和到期时间。
如何简单地编写查询内容: 实施例..
http://www.url.com/printLabel.html?product=Teriyaki&expiry=48hr
打印窗口
<script>
document.write ("Teriyaki");
document.write ("48hr");
</script>
答案 0 :(得分:0)
希望我了解您的要求,这可以帮到您。在下面的代码段中,我使用正则表达式来解析&#34;位置字符串&#34;来自窗户。
var thepath = window.location;
//here I'm just overwritting the path to make sure I have your required params in it...
thepath = "http://stackoverflow.com/questions/40793279/write-string-from-url-in-javascript?product=ThisOne&expiry=48h";
var prodPattern = new RegExp(/product=([^&]*)/);
var expPattern = new RegExp(/expiry=([^&]*)/);
console.log(prodPattern.exec(thepath)[1])
console.log(expPattern.exec(thepath)[1])
&#13;