Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 452
  • Last Modified:

Size of navigator visual basic

I'm using this code

  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
 
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {

    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
 window.alert( 'Width = ' + myWidth );
 window.alert( 'Height = ' + myHeight );

Open in new window


   The code is in JavaScript and detect the browser dimensions now I have these questions:

1.-Is there a way to use the same in Visual basic. if yes could you paste the code here?
2.-Is there a way to pass a variable from JavaScript to Visual basic if yes how with examples. For example in the above example the variable "Width" suppose has a value of 500 in JavaScript how can I pass that value to that  JavaScript variable "Width" with same name or another no matter. Is allowed use session variables I can generate from visual basic (vbscript) the session variable then load in JavaScript I can do that but after modified the session variable how can I return to visual basic is the same ti send a variable from JavaScript to Visual Basic (vbscript) I don't know how.

This is for a simple ".asp" pages I'm not using ASP.NET

Thank you

Edit by Padas:  Should be vbscript and not Visual Basic
0
coerrace
Asked:
coerrace
1 Solution
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
1.-Is there a way to use the same in Visual basic. if yes could you paste the code here?
No, Vbscript is a server side language.  Detecting the browser width is done in javascript.

2.-Is there a way to pass a variable from JavaScript to Visual basic if yes how with examples.
There is,  however you can't use it in the way you are thinking.  The way your page renders is first any of your vbscript is run ON THE SERVER.  This means any calculations, database calls and rendering of html.  Next the vbscript rendered html is merged with your static html and the full html page is rendered to the browser.  Finally, any javascript or jquery you have written will be executed.  This includes things like detecting the browser width, changing any css or adding/changing/removing/hiding/showing any elements.

This means you could have a field like,
<input id="abc" name="abc" value=""> 

Open in new window

and set it with js like
document.getElementById('abc').value = 'my_value';

Open in new window

or in jquery
$('#abc').val('my_value');

Open in new window

Now once the page is fully rendered (with javascript turned on) the input will look like below if you use your browsers console (view source will still look as hard coded)
<input id="abc" name="abc" value="my_value"> 

Open in new window

When you submit the above, you can get the value by using
response.write request.form("abc")

Open in new window

My guess is if you need to change something based on width detected  from javascript or jquery, then you should also update whatever element you are trying to target with jquery as well.

You can also use Media Queries in  your css https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Media_queries 

Let's say you have

<style>
div.foo{
   width:800px;
}
</style>
<div class="foo">Bar</div>

Open in new window

But that is too big for a 700px screen.  You can use media queries to set css for different viewports.
<style>
div.foo{
   width:800px;
}
@media (max-width: 800px) {
    div.foo{
        width:700px;
   }
}
@media (max-width: 700px) {
    div.foo{
        width:600px;
   }
}
</style>
<div class="foo">Bar</div>

Open in new window


Using a combination of javascript/jquery and css/media queries, you have a lot of options.  If by chance you are trying to build a responsive site, look into using http://getbootstrap.com/ or http://foundation.zurb.com/ as your core.  These are both responsive css grid systems with some extra responsive help.  

Please let me know if I missed something or your question is different than I guessed.
0
 
coerraceAuthor Commented:
Excellent answer thank you for the time
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now