Below is my code in Java script for adobe acrobat. How do I set my PDF, so the script will always work during printing process? At the moment when I close the document and re-open the code is not executed unless I re-open javaScript "Set Documents Actions" window..
The code works well and its set to run when "document will print"
I need it to be automated. To always execute when a user tries to print it.
// Add Watermark ON PRINT Var. Watermark "YES"
var docwtrmrk = this.info.Watermark; // get Watermark variable value : this.info.<Any EPDM Variable can be used as ref.>
var docRev = this.info.Revision; // Get Revision variable Value : this.info.<Any EPDM Variable can be used as ref.>
var cMyText = "NOT APPROVED!!! FOR REFERENCE ONLY" + "\n Printed on: " + util.printd("dd.mm.yyyy # HH:MM", new Date) + "\n REVISION NO.: " + docRev;
if (docwtrmrk == "Yes") {
// Yes, adds watermark
this.addWatermarkFromText({
cText: cMyText,
nTextAlign:app.constants.align.center,
cFont: "Helvetica-Bold",
nScale: 1,
aColor: color.red,
nRotation: 45,
nOpacity: 0.5,
bOnScreen: true,
});
app.alert("You are about to print NOT APPROVED Docuement \n Double check with engineering and Document controler \n USE FOR REF. ONLY", 1);
}
else {} // Dont add watermark
Related
I've built simple options form with 3 radio buttons.
Seems that my options.js works correctly - i.e. if I change selection of the button, close options dialog and reopen it, the selection that I made previously is restored to the correct choice.
But if I try to pick up setting from another script, using the same statement that was used in options.js, it returns "undefined" string as if there would be no variable value stored in chrome storage.
Code in options.js that works ok:
chrome.storage.local.get(['card'], function(result) {
var card = null;
if(result.card) {
card = result.card;
} else {
card = 'douay';
chrome.storage.local.set({'card': 'douay'});
}
document.getElementById("demo").innerHTML = 'Value currently is ' + card;
document.getElementById(card).checked = true;});
Code in another script (returns "Value currently is undefined"):
chrome.storage.sync.get(['card'], function(result) {
window.alert('Value currently is ' + result.card);
});
And if I set settings and read them in the same script, they work as expected - message with "Value Got! Value is This text shall be stored"
chrome.storage.sync.set({'value': "This text shall be stored"}, function()
{window.alert("Value Saved!")});
chrome.storage.sync.get('value', function(data){
window.alert("Value Got! Value is " + data.value)});
Im making a bot that is succeding to take orders with alerts and prompts. But now I want to instead show it directly on the page. Does anyone know how I can change the prompts to innerHTML in the code, and still manage to make everything function (and continusly going to the next question)?
This is my code:
// Iteration 2
alert(`Hey! Happy to serve you pizza. On our menu we have ${vegetarian.toLowerCase()}, ${hawaiian.toLowerCase()} and ${pepperoni.toLowerCase()} pizza.`)
// Iteration 3 & 5
let orderName = prompt("Enter the name of the pizza you'd like to order today.").toLowerCase()
console.log(`orderName = ${orderName}`)
let orderQuantity
while(true) {
if (checkOrderName(orderName)) {
console.log("Right type of pizza")
orderQuantity = prompt(`How many ${orderName} pizzas do you want?`)
break;
} else {
console.error("Wrong type of pizza")
orderName = prompt(`we don't have ${orderName} on the menu. Please choose something from the menu:`)
}
}
console.log(`Exited while loop. orderQuantity = ${orderQuantity}`)
// Iteration 4
let orderTotal = calculatePrice(orderQuantity, pizzaPrice)
console.log(`orderTotal = ${orderTotal}`)
// alert("Great I'll get started on your " + orderName + " right away. It will cost " + orderTotal + " kr. It will take " + cookingTime(orderQuantity) + " min.")
document.getElementById("pop-up-replacement").innerHTML = `Great I'll get started on your ${orderName} right away. It will cost ${orderTotal} kr. It will take ${cookingTime(orderQuantity)} min.`
```
Basically, what you need to do is have an html element in which you can display your message / question. Then add an input element so that users can type in their response.
Example html
<h2 id="message"></h2>
<input id="input" />
<button id="submit">Submit</button>
Then using JavaScript you can display the message by changing the innerHTML of the message element. Then when the user clicks the submit button, use the value of the input to collect their answer.
Note: This method is asynchronous, so you will have to use the addEventListener to capture clicks, unlike prompt, which pauses the execution of any JavaScript until the user has exited the prompt.
I've been writing a script that lets the user press a button three times, once the three times are up the button is to be greyed out and unclickable. I've made it so that the button cannot be clicked (using VBScript) but I want to use Javascript to also grey out at that point.
What I want to do is have javascript search for a file on the users local drive "C:/sys/" and if that file exists then grey out the button.
The issue that I having is that the only part of the file name that I know will be correct is the last two characters "-3" the beginning of the file name could be any amount of alphanumeric characters. I thought I could use a regex to find the file but I have no idea how to get the script to search for the file using the directory path + the regex. Example for the code:
function checkfile()
{
var fileLocation = "C:/sys/"
var regex = new RegExp('\w+\-3');
if(fso.FileExists(fileLocation + regex)) {
alert("File found successfully");
} else {
alert("File not found.");
}
}
window.onload = checkfile;
I thought that might work but thinking about it makes me wonder if that script is actually searching for a file called "C:/sys/\w+-3" literally rather than using the regex.
Bare in mind that this is part of a much larger script so "fso" is already defined using Set fso = CreateObject("Scripting.FileSystemObject") in VBScript.
The whole code can be found here
<script language="VBScript">
Set objShell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
System = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System\"
DisableTaskMgr
dim currentDir : currentDir = objShell.CurrentDirectory 'Finds the scripts current directory'
'TO DO: Check whether UserName method below can be used over network'
UserName = objShell.ExpandEnvironmentStrings("%USERNAME%") 'Grabs the username of the current user'
pathToConfig = currentDir & "/config.ini"
pathToKeyFile = "C:/sys/"
'Gets the current version number from config file'
If fso.FileExists(pathToConfig) Then 'Makes sure that the config file exists'
Set ConfigFile = fso.GetFile(pathToConfig) 'Config file contains only the version number'
If ConfigFile.Size > 0 Then 'This makes sure that there is a version number set inside the config file'
Set versionFile = fso.OpenTextFile(pathToConfig, 1)
Version = versionFile.ReadAll
Else
EnableTaskMgr
window.close 'If config file cannot be reached then the script will end prematurely and will be shown next time the user logs in once the config file can be reached.'
End If
Else
window.close
End If
On Error Resume Next
versionFile.close
'Searches C:/sys/ for keyfile'
If fso.FileExists(pathToKeyFile & Version) Then
EnableTaskMgr
window.close
Else
End If
sub Postpone
ChkOne = pathToKeyFile & Version & "-1"
ChkTwo = pathToKeyFile & Version & "-2"
ChkThree = pathToKeyFile & Version & "-3"
If fso.FileExists(ChkThree) Then
'Placeholder code'
MsgBox "Maximum number of Postpone attempts used. You must now choose to either Accept or Decline the Policy."
ElseIf fso.FileExists(ChkTwo) Then
'Delete file ChkTwo - Create file ChkThree'
fso.DeleteFile(ChkTwo)
Set objFile = fso.CreateTextFile(ChkThree)
window.close
ElseIf fso.FileExists(ChkOne) Then
'Delete file ChkOne - Create file ChkTwo'
fso.DeleteFile(ChkOne)
Set objFile = fso.CreateTextFile(ChkTwo)
window.close
Else
'Create file ChkOne'
Set objFile = fso.CreateTextFile(ChkOne)
window.close
End If
end sub
sub DisableTaskMgr
objShell.RegWrite System, "REG_SZ"
objShell.RegWrite System & "/DisableTaskMgr", 1, "REG_DWORD"
end sub
sub EnableTaskMgr
objShell.RegWrite System, "REG_SZ"
objShell.RegWrite System & "/DisableTaskMgr", 0, "REG_DWORD"
end sub
sub Logon 'Method only runs when user clicks "I Accept"'
On Error Resume Next
Call EnableTaskMgr
If Not (fso.FileExists(currentDir & "/store/" & LCase(UserName) & ".csv")) Then
On Error Resume Next
Set objFile = fso.CreateTextFile(currentDir & "/store/" & LCase(UserName) & ".csv", True)
objFile.close
Else
End If
Set objCSVFile = fso.OpenTextFile(currentDir & "/store/" & UserName & ".csv", 2, True)
objCSVFile.Write(UserName & "," & Now & "," & Version)
objCSVFile.Close
On Error Resume Next
fso.CreateTextFile("C:/sys/" & Version)
window.close
end sub
sub Logoff 'Method only runs when user clicks "I Decline"'
objShell.Run "shutdown /l"
end sub
</script>
<script type="text/javascript">
function checkfile()
{
var fileLocation = "C:/sys/"
var regex = new RegExp('\w+\-3');
if(fso.FileExists(fileLocation + regex)) {
alert("File found successfully");
} else {
alert("File not found.");
}
}
window.onload = checkfile;
</script>
I am having a static html page on local storage(hard disk drive). I am not using any kind of server here. Along with this I have an xml file named testng.xml which I need to edit from html on button click using javascript.
I need to replace the <include> tag with <exclude> tag or vice versa based on user selection through a checkbox on web page. And then execute the testng xml by a button click.
The function is called from the html button as below
<input type="submit" onclick="editTestNG()" value="Execute Selected Tests">
Given below is my code for editing the xml.
<script type="text/javascript">
function editTestNG()
{
xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", "testng.xml", false);
xmlHttp.send();
xmlDoc = xmlHttp.responseXML;
txt = "";
x = document.getElementsByName("check");
document.write(x.length + "<br>"); // x.length is number of checkboxes on html page
z = xmlDoc.getElementsByTagName("run")[1];
y = z.children;
document.write(y.length + "<br>"); // y.length is the number of xml child nodes
document.write(x.length + "<br>"); // x.length is number of checkboxes on html page
for(i=0;i<x.length;i++)
{
document.write("abc");
if(x[i].type == 'checkbox')
{
document.writeln("def");
if(x[i].checked == "true" && y[i].nodeName == "exclude")
{
document.writeln("ghi");
txt = y[i].getAttribute("name");
newTag = xmlDoc.createElement("include");
newTag.setAttribute("name",txt);
p = z.replaceChild(newTag, y[i]);
document.write(p.nodeName+"<br>")
document.write(newTag.nodeName + "::"+ newTag.getAttribute("name")+"<br>");
}
if(x[i].checked == "false" && y[i].nodeName == "include")
{
document.writeln("jkl");
txt = y[i].getAttribute("name");
newTag = xmlDoc.createElement("exclude");
newTag.setAttribute("name",txt);
p = z.replaceChild(newTag, y[i]);
document.write(p.nodeName+"<br>")
document.write(newTag.nodeName + "::"+ newTag.getAttribute("name")+"<br>");
}
}
}
y = z.children;
for(i=0;i<y.length;i++)
{
document.writeln("<br>"+y[i].nodeName + " ## "+ y[i].getAttribute("name")+"<br>");
}
}
</script>
The output on html page after clicking the button is as below
140
7
0
exclude ## Group_CCMS_Login
exclude ## Group_CCR_Create_New
exclude ## Group_CCR_Create_New_EngType_M
exclude ## Group_CCR_Create_New_EngType_P
exclude ## Group_Full_ID_Search
include ## Group_Run_Query
exclude ## Group_Dup_Undup
I am able to retrieve the xml file and elements in the z and y variables. Also in the 2nd for loop, the output containing xml node names and attributes is printed. But after getting xml data in y variable, I am not able to get or use any html page elements such as checkboxes.
The value of x.length is 140 initially and y.length is 7, but then x.length becomes 0 and my 1st for loop does not execute.
I am unable to understand why I can't access html elements after getting xml data.
I never tried but as per my understanding you can create a bash file and then exucute that bash file using jsp code. Add that jsp code in the HTML.
Refer:-
executing a bash script from a jsp page
Now as you said "I need to prepare a user interface in HTML with checkboxes to select or deselect the tests to run and execute them with click of a button"
For that may you need to create different testng suite and accordingly you need to create a more bash respectively.
Refer:-
http://grokbase.com/t/gg/selenium-users/139r0nszp3/how-to-run-multiple-xml-files-with-testng
I have a page in one of my ASP.NET applications (VB) that relies on a 3rd party service being live, and I'm using jQuery to display an overlay if this service is found to be down. I've been using the same approach for other warnings in the app - the difference with this one is that it needs to redirect after the user clicks the button on the warning popup to remove the overlay. For some reason I'm getting the error "Error: The value of the property 'warn_redirect' is null or undefined, not a Function object."
Any assistance is greatly appreciated! My code follows:
jQuery
function warn_redirect(msg, title, nextpage) {
// show modal div
//alert(obj.id);
$("html").css("overflow", "hidden");
$("body").append("<div id='popup_overlay'></div><div id='popup_window'></div>");
$("#popup_overlay").addClass("popup_overlayBG");
$("#popup_overlay").fadeIn("slow");
// build warning box
$("#popup_window").append("<h1>" + title + "</h1>");
$("#popup_window").append("<p id='popup_message'><center>" + msg + "</center></p>");
$("#popup_window").append("<div class='buttons'><center><button id='continue' class='positive' type='submit'>OK</button></center></div>");
// attach action to button
$("#continue").click(popup_remove_redirect(nextpage));
// display warning window
popup_position(400, 300);
$("#popup_window").css({ display: "block" }); //for safari using css instead of show
$("#continue").focus();
$("#continue").blur();
}
function popup_remove_redirect(nextpage) {
$("#popup_window").fadeOut("fast", function () { $('#popup_window,#popup_overlay').trigger("unload").unbind().remove(); });
$("body", "html").css({ height: "auto", width: "auto" });
$("html").css("overflow", "");
window.location.href = nextpage;
}
Here is the VB.NET calling code:
If Status = "DOWN" Then
Dim clsUtility As New Utility
clsUtility.Emailer("email#company.com", "email#company.com", "", "", "The Service Is Down!", "Please investigate")
Dim ScriptString As String = "<script language='javascript'>"
ScriptString += "warn_redirect('Some warning message.', 'Warning', 'AnotherPage.aspx');"
ScriptString += "</script>"
ClientScript.RegisterStartupScript(Me.GetType, "warnscript", ScriptString)
'Response.Redirect("AnotherPage.aspx?ID=" & Session("SelKey") & "&UN=" & Header1.UserNumber) //this didn't work either
End If
Try this,
If Status = "DOWN" Then
Dim clsUtility As New Utility
clsUtility.Emailer("email#company.com", "email#company.com", "", "", "The Service Is Down!", "Please investigate")
Dim ScriptString As String = "<script language='javascript'>"
ScriptString += "window.onload = function(){warn_redirect('Some warning message.', 'Warning', 'AnotherPage.aspx');};"
ScriptString += "</script>"
ClientScript.RegisterStartupScript(Me.GetType, "warnscript", ScriptString)
'Response.Redirect("AnotherPage.aspx?ID=" & Session("SelKey") & "&UN=" & Header1.UserNumber) //this didn't work either
End If
As JQuery is already included, you can also use the below statement instead.
ScriptString += "$(function(){warn_redirect('Some warning message.', 'Warning', 'AnotherPage.aspx');});"
This is because the definition of your script is loaded after the StartupScript is invoked.
You have to include your .js file before the StartupScripts in your page. Look at the "source code" in your browser, and you'll see a bunch of script tags like this:
<script src="/ScriptResource.axd?d=eoXLgy ... 847d" type="text/javascript"></script>
These tags are the scripts inserted as StartUp scripts. Make sure your script is inserted before this in your .aspx (or .master). Perhaps you'll have to include them in the head tag.
By the way, creating a global function, like you warn_redirect, it's not a good practice. You should, at least, namespace it like this:
window.MyFunctions = {
warn_redirect = function (msg, title, nextpage) { /* your code */ }
}
And call it like this: MyFunctions.warn_redirect.
In this way, you have it better organized, and avoid possible collisions with other functions with the same name.