• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

calling function from src attribute of html tag

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to be able to get my string for the src attribute from a Javascript function. I know there is a way to do this, but it has been a few years since I last did this and I can't seem to get the syntax right or something...

Currently I have a function like this...

<script language="javascript">
function getUrl(){
/* build URL here ... */
return URL;
}
</script>

Then I try to use the function like this...

<iframe src=javascript:getUrl(); width="100%" height="100%"></iframe>

This does not work though...
 
Bloo Barton
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Eric,

That method looks like it is pushing the value from the function out to the tag. I'm looking for something more re-usable. I want to be able to call the function from the tag, not push the data into the tag when the page loads.
 
Ranch Hand
Posts: 429
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure, would this work?

<script>
function getFrame1(iframe) {
var src = "http://example.com/frame1";
if (!iframe.hasBeenSet) {
iframe.src = src;
iframe.hasBeenSet = true;
}
}
</script>
.
.
.
<iframe src="" onload="getFrame1(this)" width="100%" height="100%" ></iframe>

-Yuriy
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yuriy,

I guess I was not awake on trying to figure out a way to stop the infinite loop of loading! Soon as I saw your post I said: "DUH!". I do stuff similiar on other projects of mine. LOL

Eric
 
And then the entire population worshiped me like unto a god. Well, me and this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic