• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 254
  • Last Modified:

Passing variables to iframe src

<body>
    ......
   <td class="bannerTD">
      <script>
     var clientWidth = document.body.clientWidth;
      </script>
     <iframe name="banner" class="bannerIF" frameborder="no" src="banner.asp?clientWidth=" + <script>clientWidth</script> scrolling="no">
      </iframe>
   </td>

......
</body>

As you can see im trying to pass the variable clientWidth to my asp page as an argument, except when i check in the asp page, clientWidth is equal to "" and not the proper value.......Thanks in advance
0
rowghani
Asked:
rowghani
  • 3
  • 2
1 Solution
 
jonnalCommented:
hi try

<script>document.write(clientWidth)</script>
0
 
cirtapCommented:
Hi,
I don't think you'll get around with at least two requests for the "banner" page, but in case there's no JS vailable, banner.asp can serve a default size in case the Script will be able to provide the clientWidth.
As I don't know if your banner is just the "top of your page" or an ad-link, I'll assume the latter.
Ad-Pages normally refresh themselves using <meta refresh>. I'll suggest you make "banner.asp" create a "blank page" upon first request (no args/params given) incl. a refresh of let's say 2 seconds just to load quickly and wait "what comes next".
If JavaScript is available, the script will in the "hosting page" will immediately change the banner's location with the clientWidth parameter and from this point on, banner.asp will refresh itself with ?clientWidth and whatever additional informations it needs; next banner-id etc.

The page hosting the banner:
...
<td class="bannerTD">
<!-- 1. the IFRAME with NO -->
<iframe name="banner" class="bannerIF" frameborder="no" src="banner.asp" scrolling="no"></iframe>
<!-- 2. the script FOLLOWING the IFRAME -->
<script language="JavaScript">
<!--
  // I guess this needs a fix-up to work in NS as well!
  var clientWidth = document.body.clientWidth;
  // now set the location
  banner.window.location.href="banner.asp=?clientWidth" + clientWidth;
// -->
</script>
</td>
...

However, I'd NOT use document.write() to create the <IFRAME> from script to avoid the first (kinda useless) request, but it's up to you.

Hope this helps.
CirTap
0
 
rowghaniAuthor Commented:
thanks to everybody for their help, i got it after several tries:

<td class="bannerTD">
     <script>
     var source = "banner.asp?clientWidth=" + document.body.clientWidth;
        document.write("<iframe name='banner'   class='bannerIF' frameborder='no' src='"+ source +"' scrolling='no'></iframe>");
     </script>
</td>
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
cirtapCommented:
:-) looks familiar
and makes your banner's appearance depend on JavaScript.
you may want to think a minute about my previous comment and what possibilities and flexibility you'll gain from it.

Have phun
CirTap
0
 
rowghaniAuthor Commented:
thanx cirtap,
the thing is that this script is not being used on the World Wide Web (ie. a homepage or whatnot). My company has enbeded IE in their application, and im creating a web user interface for our clients. We require that the client have IE, and therefore the banner page's appearance depending on javascript is ok.

Maybe you have some other issue about having Javascript depended page, and i would love to hear them!
Cheers

0
 
cirtapCommented:
Hi,
well thanx 4 the points then.

If you'd mentioned the intranet before... Things are *always* totally different in such a controlled environment and using document.write becomes a pretty "save" way (for the programmer/designer) to solve "problems", although not the only one.
As a hint for your (maybe) upcoming questions in EE: make clear it's for MSIE (version maybe?) in an intranet-site so the experts can give you more specific answers instead of 'generic', x-browser, www-compatible ones :-)

I don't know if disabling Scripting in MSIE itself will also affect any embedded WebBrowser-Control (WBC). If so, the "plain banner-call" may detect this and display a message. You may want to this this out.

'My' answer to JS dependant pages is simple: avoid to make one :-) in www.
No JS validation in FORMs without having validation on the server,too, no JS-only navigation, if it will make browsers w/o JS stop from accessing the site's (well planned and large) content.
Building a website is like cooking: using exotic spices are great fun - but sometimes all you need is some salt and pepper to enjoy the food.

If you "depend" solely on MSIE, go to the 'Web Develpment' area of MSDN library and check out the great extra features IE and the WBC provide compared to other browsers; HTML behaviors, HTML components, and many useful additional events, XML integration etc.
http://msdn.microsoft.com/library/default.asp

Have fun,
CirTap
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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