iframe change src | javascript

July 27, 2009 at 3:56 am 8 comments

A small snippet for the people who wanna change src of Iframe on click.

Example

<html xmlns=”http://www.w3.org/1999/xhtml”&gt;
<head>

<script type=”text/javascript”>
function changeURL(id){
alert(id);
newURL=”http://yahoo.com&#8221;;
document.getElementById(id).src=newURL;
}
</script>

</head>

<body>
<form name=”testForm”>
<iframe id=”test” name=”testName” src=”http://google.com”></iframe&gt;
</form>
<a href=”#” onclick=”changeURL(‘test’);”>dfdfd</a>

</body>
</html>

Entry filed under: Javascript. Tags: .

India in New Zealand [1st T20 Match ] javascript browser detection script

8 Comments Add your own

  • 1. kathmandu flights  |  November 18, 2009 at 12:47 pm

    how could this code be useful for me in ethical ways?

    Reply
    • 2. me  |  December 6, 2009 at 3:53 pm

      @ kathmandu flights

      ethical ways?

      – Rich Internet Applications
      – Adobe Air applications
      – more modern stuff you probably wouldn’t understand

      Reply
  • 3. izdelava spletnih strani  |  December 4, 2009 at 10:04 am

    I’m having problem when linking inside the iframe. I would like to link target=”_top” but can’t find any usefull tips. I tryied everything but simply can’t find the solution.

    Reply
  • 4. vinska klet  |  December 10, 2009 at 8:02 am

    I think it could be done but with Java script.

    Reply
  • 5. Rob  |  March 19, 2010 at 7:34 pm

    Simple and beautiful code. Many thanks. The way I’m using it is in an image gallery. Two iframes need to change on a single navigation click. The link target takes care of one change, and your most excellent code takes care of the other.

    Reply
  • 6. Shirley  |  April 12, 2013 at 1:57 am

    I enjoy, lead to I found exactly what I was looking for.
    You have ended my four day long hunt! God Bless you man.
    Have a great day. Bye

    Reply
  • 7. bank loans for bad credit  |  July 2, 2013 at 3:31 am

    So much for attempting this myself, I’ll never be able to manage it. I think I’ll just read about it.

    Reply
  • 8. vikas  |  April 22, 2014 at 10:53 am

    not working

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


Flickr Photos

The firsts lights

Lago di Braies

Survivor Mode

More Photos

Blog Stats

  • 705,777 hits

%d bloggers like this: