Page throws JavaScript runtime error: 'Function name' is undefined. IE10 only - javascript

While working on IE10, I have found that the JavaScript functions which are registered or called from the code behind are throwing exception:
"JavaScript runtime error: 'function name' is undefined".
For ex:
Code behind in the (!IsPostBack) block:
Page.RegisterStartupScript("showGCAlert", "<script language=\"javascript\">ShowGCAlert();</script>");
PageView:
function ShowGCAlert()
{
alert('GCAlert');
if(document.getElementById('hdnGCAlert').value != "1")
{
document.getElementById('divGCAlert').style.display = "Block";
document.getElementById('chkReminder').focus();
document.getElementById('btnLogin').disabled = true;
document.getElementById('Button2').disabled = true;
}
else
{
document.getElementById('divGCAlert').style.display = "none";
document.getElementById('btnLogin').disabled = false;
document.getElementById('Button2').disabled = false;
if (document.getElementById("txtUsername").value != "")
document.getElementById("txtPassword").focus();
else
document.getElementById("txtUsername").focus();
}
}
When the page loads its throws the exception even though the ShowGCAlert() exists on the dynamic page.
After continuing the exception design page shows:
<script language="javascript" src="/ABC/DEF/Scripts/Common.js"></script>
<script language="javascript">
document.body.style.overflowY="hidden";
document.body.style.overflowX="hidden";
var jsAppName ='ABC';
</script>
<script language="javascript">
function window.onresize()
{
document.cookie = "resX="
+ document.body.clientWidth
+ ";resY="
+ document.body.clientHeight
+ ";path=/";
}
window.onresize();
</script>
<script type="javascript">
ShowGCAlert();
</script>
<script language="javascript">
document.getElementById('txtPassword').focus();
</script>
In ie9 or IE10 compatibility view its working fine. Please show me where i am doing wrong.

Try placing the script at the end of the page using RegisterClientScriptBlock and call it.
Page.ClientScript.RegisterClientScriptBlock("showGCAlert",
"<script type=\"text/javascript\">ShowGCAlert();</script>");

Related

Run Javascript only when comming from specific link

I have this Javscript fade effect when opening the page, for example admin.php.
<body>
<script>
document.body.className = 'fade';
</script>
...html code...
<script>
document.addEventListener("DOMContentLoaded", function(e) {
document.body.className = '';
});
</script>
</body>
The problem is I can't figure it out how to run this script only when comming from login.php page.
For clarification, it's an effect when opening page it's white and then in about 1sec the page becomes visible, creating fade effect.
Pass along a variable in the query string. For example, link to it with admin.php?coming_from_login=1.
Then in your PHP file:
<?php if (isset($_GET['coming_from_login']) && $_GET['coming_from_login'] == '1'): ?>
<script>
document.addEventListener("DOMContentLoaded", function(e) {
document.body.className = '';
});
</script>
<?php endif; ?>
You can make use of document.referrer:
<body>
<script>
const referrerPage = document.referrer.replace(location.origin, ""); // Remove the origin to leave just the page
if (referrerPage === "/login.php") {
document.body.className = 'fade';
document.addEventListener("DOMContentLoaded", function (e) {
document.body.className = '';
});
}
</script>
...html code...
</body>

How do I get the browser to reload my script from the server each time the page is loaded?

I currently call a Perl script from my website like this to produce a Captcha image like this:
<script language="JavaScript1.2" type="text/javascript" src="http://www.MyUrl/cgi-bin/Captcha-Image.pl"></script>
And I return Captcha Image to the web page like this:
<script language="JavaScript" type="text/javascript">
<!--
document.write (CAPTCHA);
//-->
</script>
This works fine but the issue I'm having is if the user clicks back the Captcha image does not refresh and needs to do so, as after it is submitted it is no longer valid.
So I'm trying to use this:
<input type="hidden" id="refreshed" value="no"/>
<script type="text/javascript">
onload = function () {
var e = document.getElementById("refreshed");
if (e.value == "no") e.value = "yes";
else { e.value = "no"; location.reload(); }
}
</script>
But instead of refreshing the page I would like to just recall the Perl script Im already using the "Cache-Control: no-cache tag" "http://www.MyUrl/cgi-bin/Captcha-Image.pl" to print a new image I tried this with no luck:
onload = function () {
var e = document.getElementById("refreshed");
if (e.value == "no") e.value = "yes";
else { e.value = "no"; location.reload('http://www.MyUrl/cgi-bin/Captcha-Image.pl'); }
}

jQuery Freichat conflict

I'm trying to integrate the freichat module to my website, but i got this error
TypeError: $ is not a function
I tried to encapsulate it with an anonymous function passing jQuery as the parameter , like this:
(function($) {
$(document).ready(function() {
// my custom code
});
})(jQuery);
I also put jQuery instead of $ and got the below issue:
jQuery is undefined
Any idea regarding this?
Codes:
<script src="JS/jquery.js"></script>
<script language="javascript">
$(document).ready(function () {
$("#lawyerrr").select2();
$("#fromm").select2();
$("#too").select2();
});
</script>
<?php
$ses = null; // Return null if user is not logged in
if (!empty($_SESSION['user'])) {
$loggedUser = $_SESSION['user'];
}
if(isset($loggedUser['idd']))
{
if($loggedUser['idd'] != null) // Here null is guest
{
$ses=$loggedUser['idd']; //LOOK, now userid will be passed to FreiChat
}
}
//echo $ses;
if(!function_exists("freichatx_get_hash")){
function freichatx_get_hash($ses){
if(is_file("C:/wamp64/www/freichat/hardcode.php")){
require "C:/wamp64/www/freichat/hardcode.php";
$temp_id = $ses . $uid;
return md5($temp_id);
}
else
{
echo "<script>alert('module freichatx says: hardcode.php file not
found!');</script>";
}
return 0;
}
}
?>
<script type="text/javascript" language="javascipt" src="http://localhost/freichat/client/main.php?id=<?php echo $ses;?>&xhash=<?php echo freichatx_get_hash($ses); ?>"></script>
<link rel="stylesheet" href="http://localhost/freichat/client/jquery/freichat_themes/freichatcss.php" type="text/css">
Add JQuery library to your document:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Javascript function not working properly in Safari 5.1.7

On Load of Access.aspx a javascript function is called.
<head>
<title>access</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<link href="rtsBanner.css" type="text/css" rel="stylesheet">
<script language="JavaScript" type="text/javascript" src="winopen.js"> </script>
<script type="text/javascript" language="javascript">
function openLogin(site, pass) {
var loginUrl = 'login.aspx';
if (site != '' && pass != '') {
loginUrl += '?SITE=' + site + '&PASS=' + pass;
}
else if (site != '') {
loginUrl += '?SITE=' + site;
}
var popUpFeatures = 'dialogHeight: 385px; dialogWidth: 600px; edge: Raised; center: Yes; help: No; resizable: No; scroll: Yes; status: No;';
var RetVal = window.showModalDialog(loginUrl, 'null', popUpFeatures);
if (typeof (RetVal) == 'undefined') {
top.window.close();
}
else {
var RetArray = RetVal.split(',')
var ValidLogon = RetArray[0];
var MUName = RetArray[1];
if (ValidLogon == 1) {
document.location.href = 'newRequest.aspx?desc=' + MUName;
}
else {
top.window.close();
}
} // else(typeof(RetVal)
}
</script>
</head>
<body ms_positioning="GridLayout" onload="openLogin('<%=Request("SITE")%>','<%=Request("PASS")%>');">
<form id="Form1" method="post" runat="server">
</form>
</body>
</html>
This code works perfectly in IE but in safari on the login screen after I enter site name and password and hit login button it doesn't redirect me to the newRequest.aspx page instead just closes the login popup and shows a blank access.aspx page.
Editted:
This is the code on btnLogin_Click on Login.aspx.vb page
If txtSiteName.Text = "" And txtPassPhrase.Text = "" Then Return
If ValidateSiteAndPass(txtSiteName.Text, txtPassPhrase.Text) = False Then
Throw New Exception("OOPS!!! Either SiteName or Pass Phrase is Invalid, please check")
Else
Session("valid") = "true"
Response.Write("<script language='javascript'>{window.returnValue='1," + txtSiteName.Text + "'; self.close();}</script>") '''document.Form1.submit();")
Response.End()
End If
Please suggest
Thanks,
Kavita
I found the solution here.
http://forums.asp.net/t/1400811.aspx/1
The problem was due to window.showModalDialog. It doesn't work properly in Safari.. I replaced it with window.open
Thanks,
Kavita

Callback in writeCapture

I have script which I load this way:
$(funcion() {
var html = ''
html += '<script type="text/javascript" src="http://example.com/test.js"></script>'
$('#divid').html(writeCapture.sanitize(html,function(){
// if my test.js returns special content i do this:
var cap = ''
cap += '<script type="text/javascript" src="http://example.com/example.js"></script>'
$('#divid').html(writeCapture.sanitize(cap))
})
})
But I have error NOT_FOUND_ERR: DOM Exception 8. Where is my mistake?
Don't load scripts like that. Use the $.getScript() function instead:
$(function() {
$.getScript('http://example.com/test.js', function() {
// the script is loaded here => you can use it
});
});

Categories

Resources