My home page is made up of two seperate web pages - one contents and one for the actual website. When a link in the contents is clicked it loads in the main web site page.

When an external website is linked to my site it has to go to the home page so that the contents is also there.
Is it possible to have an external link which opens another page with the contents?

Hope I've explained this clearly enough :o

Martin

Dani AI

Generated

Frames are the root of the problem: the site always wants to serve the frameset (index.html) and then show a second page inside the content frame. is correct that creating a separate frameset page (exguest.html) works, and is right to warn about frames for SEO and direct hits. For a scalable solution that avoids one-off index files, have the single frameset accept a parameter or hash that tells it which inner page to load.

Put a small script in the frameset document (index.html) that looks for either a query parameter (for example ?p=Guest_book.html) or a hash (#Guest_book.html) and then sets the content frame to that value. Example (place this in the frameset document so it runs when the frameset loads):

<script>
(function(){
  function setTarget() {
    var m = location.search.match(/[?&]p=([^&]+)/), t = null;
    if (m) t = decodeURIComponent(m[1]);
    else if (location.hash) t = decodeURIComponent(location.hash.slice(1));
    if (t) {
      try { frames['showframe'].location.replace(t); } catch(e) {}
    }
  }
  if (window.addEventListener) window.addEventListener('load', setTarget, false);
  else if (window.attachEvent) window.attachEvent('onload', setTarget);
  else window.onload = setTarget;
})();
</script>

Add a tiny redirect snippet to content pages so that if they are opened outside the frameset they forward to the frameset and ask it to load them (this implements 's suggestion cleanly):

<script>
if (top === self) {
  var target = encodeURIComponent(location.pathname + location.search + location.hash);
  location.replace('index.html?p=' + target);
}
</script>

Notes and cautions: use encodeURIComponent when building external links (or use the hash form which does not require encoding by the server). If the framed content is on another domain be aware of cross-origin restrictions for scripting (setting the frame src is fine, but accessing its DOM is not). Frames still cause SEO, accessibility, bookmarking and back-button complications — consider moving to a template/SSI/PHP include or a modern layout (header/nav + main) if possible. This approach avoids creating one index per external link while keeping the existing frameset behavior.

Recommended Answers

All 7 Replies

Nope, not nearly clearly enough. It's ok, in this particular section of Daniweb, to post links to the site in question. Show us your page(s). Then explain what you want the external link to do.

What I think you're trying to do is:

mainpage

contents

Those are two separate pages. If I really like something on your contents page, and make a link to it, you really want that link to be redirected to mainpage, but to "load" whatever it was on contents that the link is to. Right?

It would help so much to see your site, please give is a link.

Sorry, I'll try again...

My site loads up with index.html

index.html is made up of 2 seperate pages - contents.html and home.html

when someone clicks a link (e.g. Guest Book) in contents.html
Guest_book.html will load up where home.html was.

So the it is always using index.html which has the code :

<frameset cols="120,*" border=0>
<frame src="contents.html">
<frame src="home.html" name="showframe">
</frameset>

Therefore, a link to index.html will always load the home page (with contents).

I want to have a link from an external site which will load contents.html and Guest_book.html in the index.

without having to write a new index.html e.g. index_Guest_book.html which would use...

<frameset cols="120,*" border=0>
<frame src="contents.html">
<frame src="index_Guest_book.html" name="showframe">
</frameset>

If you still don't get me I'll just give you a link to my website!

Martin

Ah, the joys of frames. I think that the best way to do what you want would be to set up a new page that the external site will link to; let's call it exguest.html (external guestbook). Then use the code from your index page and alter it accordingly:

exguest.html:

<frameset cols="120,*" border=0>
<frame src="contents.html">
<frame src="Guest_book.html" name="showframe">
</frameset>

Hope this helps

Mike

I not always recommend frame site for 2 main reasons:
1. not entirely search engine friendly
2. there's chance visitors find your framed page (content) rather than the index page.

I would suggest you use javascript to redirect your visitors to index.html when they accidentally come to content page directly (no frame).

Ah... answer to your question is NO, unless you set up another page to do the job like Mike suggested. Alternatively, if you know server side language, then use asp or php to create dynamic site.

To Mike:

Yeah, I thought I'd have to do that.

It's Just a bit annoying if I have to do that for any page that has an external link to it.

Thanks Anyway,
Martin

To Zipee:

How would I use Javascript to redirect someone from the contents if it was opened without a frame?

Martin

To Zipee:

How would I use Javascript to redirect someone from the contents if it was opened without a frame?

Martin

see or do you google search!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.