Detect HTTP_USER_AGENT in asp - asp-classic

I need in an asp site, detect if the device used is a tablet.
i'd like to know which user agent is use for this one
for now i do this
agent = Request.ServerVariables("HTTP_USER_AGENT")
Set reg = New RegExp
With reg
.Pattern = "(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|windows ce|pda|mobile|mini|palm)"
.IgnoreCase = True
.Global = True
End With
match = reg.Test(agent)
If match Then
session("IsMobileBrowser") = 1
Else
session("IsMobileBrowser") = 0
End If
Thanks

We are using this API to dectect mobile devices on our classic asp website and it works great.
https://code.google.com/p/mobileesp/source/browse/#svn/JavaScript
Use DetectTierTablet function to detect tablets.
Also with very few changes to the code we were able to include it server side. Just had to replace:
if (navigator && navigator.userAgent)
this.uagent = navigator.userAgent.toLowerCase();
with
if (Request.ServerVariables("HTTP_USER_AGENT").Item != null)
this.uagent = Request.ServerVariables("HTTP_USER_AGENT").Item.toLowerCase();

Related

Python webdriver switch from main window to popup screen (not Java alert) and login

Here is the window I need to enter new password and repeat it again and click 'create'.
My code so far:
createLogin = wait.until(EC.presence_of_element_located((By.XPATH, '//*[#id="Item.MessageUniqueBody"]/div/div/div/div/div[2]/div[2]/a')))
createLogin.click()
time.sleep(10)
try:
newPassword = self.driver.find_elements_by_xpath('//*[#id="editNewUser_newPassword"]')
newPassword1 = self.driver.find_elements_by_xpath('//*[#id="editNewUser_newPasswordRepeat"]')
newPasswordForm = self.driver.find_elements_by_xpath('//*[#id="editNewUserPasswordForm"]/table/tbody/tr[1]/td[1]')
self.driver.switch_to.active_element(newPasswordForm)
time.sleep(3)
newPassword.send_keys('123')
newPassword1.send_keys('123')
time.sleep(2)
# createLog = wait.until(
# EC.presence_of_element_located((By.XPATH, '//*[#id="editNewUserPassword_save"]')))
# createLog.click()
# time.sleep(5)
except NoAlertPresentException as e:
time.sleep(2)
myAccount = wait.until(
EC.presence_of_element_located((By.XPATH, '//*[#id="easMyAccount1"]')))
myAccount.click()
time.sleep(5)
This is the problem.
You are using find_elements_by_xpath rather than find_element_by_xpath
plural vs singular.
find_elements_by_xpath: it gives you a list of web elements with matching identifier.
find_element_by_xpath: it gives you a first web element with matching identifier.
newPassword = self.driver.find_element_by_xpath('//*[#id="editNewUser_newPassword"]')
newPassword1 = self.driver.find_element_by_xpath('//*[#id="editNewUser_newPasswordRepeat"]')
newPasswordForm = self.driver.find_element_by_xpath('//*[#id="editNewUserPasswordForm"]/table/tbody/tr[1]/td[1]')
#gauurang Answer is right, But You have to used find_element_by_xpath, also as your xpath suggested you have id to locate the webelements so it is always better to use id over xpath
Also your xpath are correct
newPassword = self.driver.find_element_by_id('editNewUser_newPassword')
newPassword1 = self.driver.find_element_by_id('editNewUser_newPasswordRepeat')
newPasswordForm = self.driver.find_element_by_xpath('//*[#id="editNewUserPasswordForm"]/table/tbody/tr[1]/td[1]')

Check if Image Exists on Remote Site ASP.NET VB

I'm trying to get my website to detect if an image exists on the server, display if it does, if it doesn't display another image (which is just called blank.png).
I have tried to use Server.MapPath with relative pathings but havent been able to get it to work. When using Server.MapPath and checking in the broswer after the page has loaded i uses the full path of the file (eg G:\domain\path\blank.png).
If i use The normal path (Dim sImagePath As String = "\Images\DriversNew\"'). The image will display, but the check for whether the image exists or not always returns false. I'm assuming its to do with the physical location of the file.
'Dim sImagePath As String = Server.MapPath("Images/DriversNew/")
Dim sImagePath As String = "\Images\DriversNew\"
Dim sHeadshot As String = sImagePath & dsDriver.Tables("Driver").Rows(0).Item("Name") & ".png"
If File.Exists(sHeadshot) Then
imgDriver.ImageUrl = sHeadshot
Else
imgDriver.ImageUrl = sImagePath & "Blank.png"
End If
Any advice? I know its something simple, but with the reading ive been doing it hasnt been able to get it working on the site.
Thanks, much appreciated!
Assuming that your database column Name contains only the short filename (i.e. no directory path information or folder names) then you can do this:
String nameFromDatabase = (String)dsDriver.Tables("Driver").Rows[0]["Name"] + ".png";
String appRootRelativeHttpResourcePath = "~/Images/DriversNew/" + nameFromDatabase;
String localFileSystemPath = Server.MapPath( appRootRelativeHttpResourcePath );
if( File.Exists( localFileSystemPath ) ) {
imgDriver.ImageUrl = appRootRelativeHttpResourcePath; // you can specify app-root-relative URLs ("~/...") here
}
else {
imgDriver.ImageUrl = "~/Images/DriversNew/Blank.png";
}

imageresizer.Plugins.Watermark on classic asp

I need to use this plugin to add watermarks to images using classic ASP. I had this work partially using this code:
dim o, b, wm, layer,textlayer
Set b = CreateObject("ImageResizer.Configuration.Config")
Set wm = CreateObject("ImageResizer.Plugins.Watermark.WatermarkPlugin")
Set textlayer = CreateObject("ImageResizer.Plugins.Watermark.TextLayer")
Set layer = CreateObject("ImageResizer.Plugins.Watermark.Layer")
textlayer.Text = "Yeees"
textlayer.fontSize = 50
layer.fill = True
set layer("dd") = textlayer 'THIS IS FAILING
wm.NamedWatermarks("sfdf") = layer("dd") 'THIS IS FAILING TOO
wm.Install(b)
b.BuildImage "C:\lg1_1361_44.jpg", "C:\lg1_1361_44_WATER.png", "watermark=tessst&format=png"
Why are you creating an instance of Layer? TextLayer and ImageLayer are the classes you want to work with
I would drop everything related to 'layer' and try this instead.
textLayer.fill = True
wm.NamedWatermarks("sfdf") = textLayer
You'll also need "watermark=sfdf" instead of "tessst"

adobe acrobat XI pro javascript

i am calling an javascript function when out of focus on the form field. So what i am tying to do is the if i ticked required this field as required field it will have a red border around it, can i write a script to remove the required option when there are value inside the field?
var thisValue = this.getField("companyName").value;
var regexLetter = /[A-Z]+$/;
var Icon = "0"; //0 — Error (default) // 1 — Warning // 2 — Question // 3 — Status
var Type = "0"; //0 — OK (default) // 1 — OK, Cancel // 2 — Yes, No // 3 — Yes, No, Cancel
if (thisValue == ""){
app.alert({
cMsg:"this is an warning",
cTitle: "thsi is title",
nIcon: Icon,
nType: Type
})
} else if(!regexLetter.test(thisValue)){
app.alert('Type alphanumeric character');
}
This is going to be rather late, but this is how I do it in my documents:
var _companyName = this.getField("CompanyName");
_companyName.required = (_companyName.value === "");
You can also impose other dependencies, like:
var _companyName = this.getField("CompanyName"),
_companyLicense = this.getField("CompanyLicense");
_companyLicense = ((_companyLicense === "")
&& (_companyName !== ""));
Having your scripts split into a couple of files could help. I use a "shared" script which contains a vast majority of the logic and the a "specific" script to round of each individual document. Also, make sure when adding the scripts to just name them 1, 2, 3, etc. in the correct order or Acrobat will be stupid. Hope this helps you.

firefox won't convert string to number in flex

I making a web app in Flex using global coordinates
I get the coordinates as strings from a web service then I do something like this:
latStr:String = "28.7242100786401";
longStr:String = "-106.12635420984";
var cLat:Number = new Number(latStr);
var cLong:Number = new Number(longStr);
This works PERFECT on IE and chrome, from the web server and when debugging locally, but Firefox just works when debugging locally and not from the web server, in the web server cLat and cLong return "NaN".
check it out yourself, it should pop up an alert when you click on a result:
http://mundobuk.com/prueba/mapa/main.html?buscar=oxxo
so I tried using parseFloat(), but it rounds cLat to 28 and cLong to -106 :(
Then I tried separating the decimals form integers, like from my example 28 and 7242100786401 then divide 7242100786401/10000000000000 = 0.7242100786401
having 2 numbers 28 and 0.7242100786401 I add them up
28 + 0.7242100786401 = 28.7242100786401
here is in code form:
var latArr:Array = latStr.split(".");
var longArr:Array = longStr.split(".");
var latDivStr:String = "1";
for (var i:int= 0; i< latArr[1].length; i++){
latDivStr += "0";
}
var longDivStr:String = "1";
for (var j:int = 0; j< longArr[1].length; j++){
longDivStr += "0";
}
var cLat:Number = parseFloat(latArr[0]) + arseFloat(latArr[1])/parseFloat(latDivStr);
var cLong:Number = parseFloat(longArr[0]) - parseFloat(longArr[1])/parseFloat(longDivStr);
again, this way works great everywhere, just not in firefox in the web server >_>
anyone have any ideas? im going crazy whit this #_#
Comma is the separator for many European countries, so it's most likely the regional configuration on either the server or the client.
I have never hear of such an error as The Flash run-time is supposed to make the different browsers and OS's interpret the SWF the same way. I will say that I don't believe you should be using "new" in-front of your Number casting.
latStr:String = "28.7242100786401";
longStr:String = "-106.12635420984";
var cLat:Number = new Number(latStr);
var cLong:Number = new Number(longStr);
This should be:
var cLat:Number = Number(latStr); //Number is right because its a Floating Point, but remove new.
var cLong:Number = Number(longStr); //Number is right because its a Floating Point, but remove new.
I tested the using the following and saw no rounding take place.
var latStr:String = "28.7242100786401";
var longStr:String = "-106.12635420984";
trace(parseFloat(latStr)); //Outputs: "28.7242100786401";
trace(parseFloat(longStr)); //Outputs: "-106.12635420984";
trace(Number(latStr)); //Outputs: "28.7242100786401";
trace(Number(longStr)); //Outputs: "-106.12635420984";
I do not see why you require this workaround. Also I use firefox as my main browser and your site seems to be working just fine.
Cheers.
I finally found out why its not working, for some reason in firefox instead of reading a dot (.) it reads a comma (,) from the web service (done in vb.net)
locally it reads it as a dot too, not online, so I suppose it has to do something with my IIS server O_o
hope this helps someone out there...

Resources