Showing posts with label Java Script. Show all posts
Showing posts with label Java Script. Show all posts

Wednesday, October 3, 2012

DatePicker Calendar Appears on Top of Page

Problem:
On page load, datepicker calendar appear on top of a web page which contains datepicker textbox (either visible or hidden).
This issue appears to be happening on Chrome browser. Some may experience it in Internet Explorer.

Source of the problem:
1. There could be more than 1 element on the page which use the same ID.
2. Another possibility is that this is a bug in some of the versions of jQuery style or script.

Solution:
Either change the ID of the elements with the same IDs if this is the issue.
If the issue is with the jQuery style, add this code to hide the DatePicker calendar when the page is first loaded:

<style type="text/css">
    #ui-datepicker-div { display: none; }
</style>
Share:

Thursday, September 13, 2012

GetJSON Only Runs Once

Problem:
$getJSON() method only runs once

Solution:

If you are using jQuery, and multiple $.getJSON() methods are called in the web page, but can only get one of the getJSON method working, then you will need to add in this code to refresh the cache, before each of the getJSON method.

$.ajaxSetup({ cache: false });

PS: This problem usually occurs when running the web page from Internet Explorer web browser. The same problem should not be encountered when running it from Chrome.
Share:

Tuesday, July 31, 2012

Check if a Function Exists in Javascript

There are times when we want to call a JavaScript function, and in certain circumstances, we want to make sure that the function does exist. e.g. When a dialog window can be opened from more than one page. And, we want to refresh the component of the the parent page from the dialog window. Thus, we need to check if the function really exists.

This is a simple yet useful example to check if a function exists in JavaScript.


<input type="button" onclick="checkFunctionExist();" value="Check Function Existence" />

<script type="text/javascript" language="javascript">

 function testFunction() {

 }

 function checkFunctionExist() {
  if (window.testFunction) alert('testFunction exists');
  else alert('testFunction does not exist');

  if (window.nonExistantFunction) alert('nonExistantFunction exists');
  else alert('nonExistantFunction does not exist');
 }

</script>


To check whether a function exists on the parent page (the page which opened the dialog window), use:

if(window.opener.testFunction) alert('testFunction exists');
else alert('testFunction does not exist');

Share:

Friday, March 18, 2011

Object tag not recognized inside form tag

Problem: When developing a page in ASP.NET, an object tag (<object>) is not recognized when it is placed in an HTML form tag (<form>).

e.g.
<html>
<head>
   <script type="text/javascript" language="javascript">
    function readScript()
    {
        Card.Connect();
    }
   </script>
</head>


 <body color=white>
    <form name="frmRead" id="frmRead">
        <object id="Card" name="Card" classid="abcDll.dll#abcDll.Card" style="display:none" ></object>
        <input type=button value="Read Card" onClick="readScript();"></td>
    </form>
 </body>
</html>

Solution: Inside the <form> tag, <object> element is out of scope. Instead of directly calling the id of the object, get the id using javascript.
function readScript()
    {
        var cardObj = document.getElementById("Card");
        cardObj.Connect();
    }

Special thanks to StackOverFlow :D
Share:

Wednesday, March 16, 2011

Running ActiveXObject from Javascript

Problem: Can't run ActiveXObject from Javascript
Error: System.Security.Permissions.SecurityPermission

This error occurs when you are trying to run ActiveXObject / dll using Javascript.


Solution:
A. Setting the security for the internet browser, i.e. Internet Explorer
1. Using Internet Explorer, set the security to low: Goto menu Tools -> Internet Options.
2. Goto tab Security.
* Under Internet zone, set security level to Low. Click Custom level button, in ActiveX controls and plug-ins section, Enable Script ActiveX controls marked safe for scripting*, then click OK.



* Under Local intranet zone, click Custom level button, enable things under ActiveX controls and plug-ins section, and the most important one, Enable Script ActiveX controls marked safe for scripting*, then click OK.



B. Setting .Net Framework 2 Configuration
1. Make sure you have .Net Framework 2 SDK installed on your computer. You may want to install it if you have not had it installed on your computer.
2. Goto control panel -> Administrative Tools -> open Microsoft .NET Framework 2.0 Configuration.
3. On the Tasks, click Configure Code Access Security Policy -> Adjust Zone Security -> Make changes to this computer, and Next. Set My computer & Local Intranet to Full trust, then Next -> Finish.




Restart the Internet Explorer, then try running the Web page again.

PS: While it is not recommended to run untrusted ActiveX Object, because it may cause security leak; this is a workaround to solve the problem in case it is necessary to run the ActiveX Object on client side.
Share:

Wednesday, August 11, 2010

Anti Java Script Error

You may often find sites with Java Script errors in it.

With this portion of code, you can get rid of Java Script errors on your site.
I suggest using this error handler wisely ^^

Code:
<script type="text/javascript">
//Stop Error : No Time For joke! Anti JS error
//START :: Error Handler ModalPopUpDialog
function errorHandler(msg, file, line) {
return true;
}
window.onerror=errorHandler;         
//END
</script>
Share:

Friday, July 23, 2010

Java Script Code to Refresh Page

Java Script code to refresh page:
In this case, it is used to refresh a particular web page every 10 seconds. Modify the part between the tag body as needed.

<html>
<head>
<script type="text/JavaScript">
<!--
function timedRefresh(timeoutPeriod) {
 setTimeout("location.reload(true);",timeoutPeriod);
}
//   -->
</script>
</head>
<body onload="JavaScript:timedRefresh(10000);">
<iframe src="web_page" width="page_width" height="page_height"></iframe>
</html>


web_page = The URL address of the page
page_width = Page width
page_height = Page Height
Share:

You may be intersted in

Related Posts

Updating Table Containing Xml Column via LinkedServer

If you are trying to update a table containing XML column via Linked Server in SQL Server, and you are not able to, you are not alone. There...

About Me

My photo
Is an ordinary man, with a little knowledge to share and high dreams to achieve. I'd be glad if I can help others, 'coz the only thing for the triumph of evil is for a good man to do nothing.

About Blog

You can find a lot of debugging and deploying problems while developing applications in .NET and Visual Basic here. There are also some querying tips in SQL and typical source codes which might be useful shared here.

Popular Posts

Blogroll

Followers

Leave a Message