Friday, November 15, 2013

Access Server-Side Variables, Property In JavaScript: C#




Accessing Server-Side Variables, Property In JavaScript: C#

At times there may be a requirement to access the server-side variables JavaScript. To achieve the same we can follow the following:

The language used for server-side variable is c#.

For a server-side variable to be accessed in JavaScript, the variable declared must be public.

Server-Side C# Code:

 public string strTempVar = "some value";  

JavaScript Code:

 <script type="text/javascript" language="javascript">  
   var strTempVarValue = "<%= strTempVar%>";  
   alert(strTempVar);  
 </script>  


The script written would give you the value in javascript.



The same can be used for accessing property as well.

Regards
Vivek Joshi

Tuesday, October 29, 2013

window.close in Firefox

In our programming and scripting world we many times come across requirements that do not find a way out, and are finally pushed in a category of Issues that cannot be resolved.

Similar thing came to me this morning when i had to close a browser tab on clicking a link on the page.

No big deal ;)

Within few minutes i scripted something as under:

 <script language="javascript" type="text/javascript">  
 function closeWindow()  
 {  
   window.close();  
 }  
 </script>  

and then i called the JavaScript function in my page's html. All worked well.

It all started when i accidentally checked my page in Mozilla Firefox. With all tweaks and all irrelevant script code written there was no way out.

*Some scripts i tried by searching on web. all commented script is what i tried. Nothing happenned.

 <script language="javascript" type="text/javascript">
 function closeWindow()  
 {  
   /* 1  
   window.open('','_parent','');  
   window.close();  
   window.open('','_self','');  
   window.close();  
   */  
   /* 2  
   window.addEventListener("beforeunload", function (e) {  
   var confirmationMessage = "\o/";  
   (e || window.event).returnValue = confirmationMessage;     
   return ConfirmationMessage;  
   });  
   */  
     /* 3  
     this.focus();  
   self.opener=this;  
   self.close();  
    */   
   /* 4  
   window.open('javascript:window.open("", "_self","");window.close();', '_self');  
   */  
   /*  
   var Browser = navigator.appName;  
   var indexB = Browser.indexOf('Explorer');  
   if (indexB > 0) {  
    var indexV = navigator.userAgent.indexOf('MSIE') + 5;  
    var Version = navigator.userAgent.substring(indexV, indexV +1);  
    if (Version >= 7) {  
     window.open('', '_self', '');  
     window.close();  
    }  
    else if (Version == 6) {  
     window.opener = null;  
     window.close();  
    }  
    else {  
     window.opener = '';  
     window.close();  
    }  
   }  
   else {  
   window.close();  
   }  
   */  
 }
 </script>  
 

Then i came across few things that i had ignored, like window.close works only for browser windows that were opened using script, which means that you can close a browser window using window.close only if you had opened it using window.open. But nevertheless IE (Internet Explorer) is an exception.

I am not sure whether this is a loophole or is a functionality provided which any other browser does not have. In IE you can close a browser window using window.close even if it is not opened using window.open.

While searching i came across the following:
 dom.allow_scripts_to_close_windows  

This is a FireFox pref in about:config file of FireFox, by default its default value is false and it does not allow to close a browser window using window.close if it is not opened using window.open.

If this value is changed to true, then it works fine. But i could not find a way to change it programmatically and more over no one would want an application to change his/her system's application settings.

On your local environment you can change this value to true and check. It works. You can access the pref as mentioned:

 1) Type about:config in the Firefox address bar  
 2) Look for dom.allow_scripts_to_close_windows [default value is set to false]  
 3) Double click this pref to set it to true.  

This would allow the window.close for browser window not opened using window.open.

So this was some research i did and there was no option i could find to close the browser window in FireFox. If you guys have come across similar situation and were able to solve it, i request you people to please share the valuable information.

Regards
Vivek Joshi

Saturday, May 9, 2009

MCA IGNOU 1st Semester Assignments 2009

Please DownLoad the following Solved Assignments :

MCS-11 MCS-12 MCS-13 MCS-14 MCS-15 MCS-16 MCS17

DownLoad Assignments : DownLoad Link

Few Questions are remaining in MCS-12 MCS-13 AND MCS-14 , which i'll be posting in few days.....

please let me know if you have doubts in any answer.....

regards
vj