Solved

Size of navigator visual basic

Posted on 2014-07-25
3
439 Views
Last Modified: 2014-07-27
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
Comment
Question by:coerrace
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 53

Accepted Solution

by:
Scott Fell,  EE MVE earned 500 total points
ID: 40221058
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
 

Author Closing Comment

by:coerrace
ID: 40222726
Excellent answer thank you for the time
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
The purpose of this video is to demonstrate how to make a WordPress Site faster and smaller in size by cleaning up the database. This will be demonstrated using a Windows 8 PC. Plugin WP Optimize will be used. Go to your WordPress login page. T…
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question