Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

calling function from src attribute of html tag

 
Bloo Barton
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Yuriy Zilbergleyt
Ranch Hand
Posts: 429
  • Mark post as helpful
  • send pies
  • 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
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic