Script to dynamically change the source of an iframe tag

Posted by Ukavi on Stack Overflow See other posts from Stack Overflow or by Ukavi
Published on 2011-11-23T09:47:27Z Indexed on 2011/11/23 9:50 UTC
Read the original article Hit count: 303

Filed under:
|
|
|
|

I want a code that will dynamically change the source of an iframe tag when a hyperlink is clicked for example I have one master page that should load content from other web pages using the iframe tag when a hyperlink is clicked but I don't know how to do it. Here is my code

<html>
<head>
<title>
</title>
<style type="text/css">
 #content{

    margin-right:30%;

    margin-bottom: 10px;

    padding: 10px;

    border: 1px solid #000;

    margin-left:17%;

    background-repeat:no-repeat;

    width:686;

    height:640;



         }
</style>

<script type="text/javascript">


function hyperlinkChanger(hyperLink)

{



switch (hyperLink)

    {

        case "home":



        var url="home.html";
        return url;
        break;


        case "about_Us":

        var url="about_us.html";
        return url;

        break;


        case "contact_Us:
        var url="contact_us.html";
        return url;

        break;

             }

}


</script>


</head>
<body>
<a href="home.html" name="home" onClick="hyperlinkChanger('home')">Home</a>
<br />
<a href="about_us.html" name="about_Us" onClick="hyperlinkChanger('about_Us')">About Us</a>
<br />
<a href="contact_us.html" name="contact_Us" onClick="hyperlinkChanger('contact_Us')">Contact us</a>
<br />

<div name="content">

<!--please help me write a method to call the output of the funcion hyperlinkChanger-->
<iframe src="hyprlink function" width="600" height="300">
</iframe>
</div>
</body>
</html>

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about html