There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Software Development
Tag Cloud
audio blue screen boot bsod computer cpu crash dell desktop driver drivers error excel external hard drive firefox freezes freezing hard drive hardware hijackthis internet internet explorer itunes laptop mac malware motherboard mouse network networking outlook 2007 power printer problem ram router screen slow sound trojan usb virus vista vista 32-bit windows windows vista windows xp winxp wireless wmp
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
[SOLVED] javascript problem in frames


Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
carolsm's Avatar
Member with 33 posts.
 
Join Date: Nov 2003
14-Nov-2003, 03:46 PM #1
javascript problem in frames
I'm trying to use a javascript to get all pages in my site to open within the main frameset, even if the user comes in from a search engine on something other than the home page. This script goes in the frameset page:


<SCRIPT LANGUAGE="JavaScript">
<!--

var ar0 = "frame1.html";
var ar1 = "frame2.html";


var str = location.search;
var pos = str.indexOf("&");
if (pos != -1) {
var num = str.substring(pos + 1, str.length);
window["ar" + num] = str.substring(1, pos);
}

// -->
</SCRIPT>
</HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--

document.write(
'<FRAMESET COLS="200, *">',
'<FRAME SRC="', ar0, '" NAME="menu">',
'<FRAME SRC="', ar1, '" NAME="main">',
'</FRAMESET>'
);

// -->
</SCRIPT>


and this one goes in each page that has to open in the frameset:


<SCRIPT LANGUAGE="JavaScript">
<!--

if (top.location.href.indexOf("frameset.html") == -1)
top.location.href = "frameset.html?mainpage.html&1";

// -->
</SCRIPT>


It works just fine if the page I am trying to force into the frameset is in the same directory as the frameset. However, if I try to force a page from a sub-directory into the frameset, it doesn't work; it just opens in a full window. I have tried all combinations of "../" on the two frameset.html references in the head of the page I am trying to force, but that doesn't seem to be enough. What other bit of code needs to be changed to get "subfolder/subpage.html" to be forced into the framset?
AcaCandy's Avatar
Computer Specs
Administrator with 102,677 posts.
 
Join Date: Jan 2001
Location: Las Vegas, NV & Acapulco, Mexico
Experience: Advanced
15-Nov-2003, 09:21 AM #2
Hi Carol and welcome.

I saw your request to move this, I believe this is the best place for it at the moment.

This post will bump it back to the top again for folks to have another look.
Shadow2531's Avatar
Distinguished Member with 2,629 posts.
 
Join Date: Apr 2001
15-Nov-2003, 10:13 AM #3
Just don't use relative URIs in the javascript contained in the files in the subfolders.

e.g.

If you go to the page http://www.yoursite.com/test/sub.htm.

In the sub.htm javascript you force the location like this.

'../index.htm?http://www.yoursite.com/test/sub.htm'

(where index.htm is your frameset page)

You just have to make sure your location.search code is set up to handle the full URI.

You could also use javascript to get the URI of the subpage an store it in a variable to use. That way the site will be portable and you won't have to change the static URIs in the javascript for the subpages.

So in the javascript of your subpage, you could have something like this. (depending on the method you use to force frames).

PHP Code:
<script type="text/javascript">
<!--
x=location;
var 
correct_frame + (parent.menu 0);
if (
parent.location.href == self.location.href || !correct_frame)
window.location.href '../index.htm?' x;
//-->
</script> 
That example was part of a force frame for a 3 frame frameset.

If you're posting a link somewhere of one of your subpages or any other page besides the default frame, you would want to put the full uri after the question mark anyways.

Now if you don't like having the full URI of the subpage, you can make the javascript in your frameset page better.

for example, in the sub.htm page referred to above, you could use window.location.href='../index.htm?sub.htm';

Then you would have to setup the javascript in your frameset page to know that if sub.htm comes after the question mark, "test/sub.htm" should be loaded in the frame.

Doing it that way would still allow the site to be portable and allow you to have whatever alias you want for each sub page.

e.g index.htm?this_is_cool could take the vistor to some subfolder or whatever.
__________________
10 ? "a line as the unending horizon"
20 ? "a curve as the rolling hillside"
30 ? "a point as a distant bird"
40 ? "a ray as the rising sun"
run

Last edited by Shadow2531 : 15-Nov-2003 10:53 AM.
carolsm's Avatar
Member with 33 posts.
 
Join Date: Nov 2003
15-Nov-2003, 01:10 PM #4
Thanks. I think I had already tried the full URL, and just tried it again, and it doesn't work that way either. It just shows the page from the subfolder in a full window. You did say "You just have to make sure your location.search code is set up to handle the full URL" which may be the problem (I got this code off of a website; I don't really speak Java), and I don't know how to do that. Help again?

Thanks!
carolsm's Avatar
Member with 33 posts.
 
Join Date: Nov 2003
15-Nov-2003, 06:45 PM #5
Never mind! I just found an extra "../" that was getting in the way. Using the absolute URL to force the page into the frameset worked.

Thanks for your help!
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 07:52 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.