Get the latest news, exclusives, sport, celebrities, showbiz, politics, business and lifestyle from The VeryTime,Stay informed and read the latest news today from The VeryTime, the definitive source.

How to Override an IFrame in JavaScript

13
    • 1). Create a new HTML file in an editor or using the Notepad. For example, type:

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

      <html xmlns="http://www.w3.org/1999/xhtml">

      <head>

      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

      <title>Overriding iFrame</title>

      </head>

      <body>

      </body>

      </html>

    • 2). Add an iFrame to the Web page and assign an ID to it. Add a button to the Web page to override the iFrame. For example, between the HTML "<body>" tags, type:

      <form><input type="button" name="override" value="Override" onclick="changeIFrame()" /></form>

      <hr/>

      <iframe src="http://www.example.com"></iframe>

    • 3). Create a JavaScript function to override the contents of the iFrame and insert it between the "<head>" tags in the HTML document. For example, type:

      <script type="text/javascript">

      function changeIFrame() {

      var cur = document.getElementById("frame1").src;

      if (cur.match(/yahoo/))

      document.getElementById("frame1").src = "http://google.com";

      else

      document.getElementById("frame1").src="http://yahoo.com";

      }

      </script>

Source...
Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time

Leave A Reply

Your email address will not be published.