Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding frames in the <body>

Status
Not open for further replies.

ayersart

Technical User
Dec 21, 2004
69
US
Is there a way to add a frame, or show another webpage in the <body> tags? I do not have access to the <head> tags. I have to work on this website which is hosted by another company, and the only thing I can edit is the <body> of the page. I want it to show a differnt page, so i was going to add a frame. Is it possible to do that, or something similar to the same effect?
 
Thanks.. now how would I create a link to the page that has the iframe, and have it show a different web page in the iframe?
 
Hi ayersart,

The trick is to give the IFRAME a name and to tell the anchor where to target the link.

Have a look at this example:
Code:
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
  <title>Specify which IFRAME to load link in</title>
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
  <meta name="author" content="dkdude" />
  <style type="text/css">

    body {
      text-align : center;
    }

    #myLeftFrame {
      height       : 60%;
      width        : 40%;
      margin       : 5%;
      border       : solid 1px black;
      position     : relative;
      float        : left;
    }

    #myRightFrame {
      height       : 60%;
      width        : 40%;
      margin       : 5%;
      border       : solid 1px black;
      position     : relative;
      float        : left;
    }

  </style>
</head>

<body>

  SEARCH WITH
  <br />
  <a href="[URL unfurl="true"]http://www.google.com"[/URL] target="myLeftFrame">Google</a> -
  <a href="[URL unfurl="true"]http://www.altavista.com"[/URL] target="myLeftFrame">Altavista</a> -
  <a href="[URL unfurl="true"]http://www.a9.com"[/URL] target="myLeftFrame">A9</a> - in LEFT frame
  <br />
  <a href="[URL unfurl="true"]http://www.google.com"[/URL] target="myRightFrame">Google</a> -
  <a href="[URL unfurl="true"]http://www.altavista.com"[/URL] target="myRightFrame">Altavista</a> -
  <a href="[URL unfurl="true"]http://www.a9.com"[/URL] target="myRightFrame">A9</a> - in RIGHT frame
  <hr>
  <iframe src="#" id="myLeftFrame" name="myLeftFrame"></iframe>
  <iframe src="#" id="myRightFrame" name="myRightFrame"></iframe>


</body>
</html>
Or you can define a default target for ALL your links by adding [tt]<base target="yourIFRAME">[/tt].

This is how it coule look like:
Code:
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
  <title>Open ALL links in the IFRAME</title>
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
  <meta name="author" content="dkdude" />
  <style type="text/css">

    body {
      text-align : center;
    }

    #myFrame {
      height   : 60%;
      width    : 80%;
      margin   : 5%;
      border   : solid 1px black;
    }

  </style>
</head>

<body>

  <base target="myFrame">

  SEARCH WITH : 
  <a href="[URL unfurl="true"]http://www.google.com">Google</a>[/URL] -
  <a href="[URL unfurl="true"]http://www.altavista.com">Altavista</a>[/URL] -
  <a href="[URL unfurl="true"]http://www.a9.com">A9</a>[/URL]
  <hr>
  <iframe src="#" id="myFrame" name="myFrame"></iframe>

</body>
</html>

There are four pre-defined target names you can use :

[tt]target="_self"[/tt] will open the link in the same windows (as the link is in)

[tt]target="_blank"[/tt] will open the link in a new window

[tt]target="_parent"[/tt] will open the link in the parent window (one window level above in a frameset)

[tt]target="_top"[/tt] will open the link in the top window (top level window in a frameset)

And (finally) here's a reference on the <a> tag :


Regards


Jakob ;-)
 
Does iframe HAVE to reference to another webpage? Or can it be treated like a table to have the iframe's content be in the same html file?
 
Yes it HAS to reference another page.

Wow JT that almost looked like you knew what you were doing!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top