PDA

View Full Version : Target page and IFRAME from a totally separate page (?)


Gordo
08-26-2002, 05:42 AM
I've searched CodingForums and the old WA for help. I found some info, but no solutions...

from glenngv on the following thread (http://www.codingforums.com/showthread.php?s=&threadid=4002&highlight=link+target+iframe):function toIframe(page,target){
window.open(page,target);
}

then in your links:
<a href="link0.htm" target="if0" onclick="toIframe('link1.htm','if1')">TEXT</a>I also found something along the lines of what I might need in this thread (http://www.codingforums.com/showthread.php?s=&threadid=3442&highlight=link+target+iframe) from beetle and vladdy...but I'm thinking the part about "top.frames" isn't what I need:make links as follows:

<a href="page2.html?frame=page3.html">page3 in page 2</a>
<a href="page2.html?frame=page4.html">page4 in page 2</a>


<script>
var qString = top.location.search.substring(1);
var temp = qString.split(/[=]/);
var nUrl = temp[1];
function initIframe()
{
top.frames['IF1'].location.href=nUrl;
}
</script>
</head>
<body onload="initIframe();">What I need......
I have main navigation links (included on every page). On one page (services.html), I have an embedded iframe. The links on services.html open up in this iframe (name="contents"). But, a couple of the main navigation links will need to open up their specific target inside the iframe...in the services.html page.I can't find a solution anywhere!

I really need this to work before I can move forward with the project.

mouse
08-26-2002, 05:57 AM
Originally posted by Gordo
What I need......
I have main navigation links (included on every page). On one page (services.html), I have an embedded iframe. The links on services.html open up in this iframe (name="contents"). But, a couple of the main navigation links will need to open up their specific target inside the iframe...in the services.html page.I can't find a solution anywhere!

I really need this to work before I can move forward with the project.Use a url string

So the iframe is like: <iframe name="contents" src="<? echo($page".html"); ?>" width="200px" height="300px"></iframe>

And the links to the pages within the service.html (<--change that to .php) look like: http://www.domain.com/services.php?page=whatever

That way whatever.html will be opened in the iframe within the services page.

If you've not got php capabilites then ignore all of the above and good luck in your endeavour :o ;)

Gordo
08-26-2002, 06:09 AM
Have no idea if PHP is available to me. How would I know and/or find out? Do only certain web hosts support it? I've never used it before.

Anyway, I'll try your solution in a moment. For now, I'm uploadinga screenshot just in case anyone needs a 'visual'.

mouse
08-26-2002, 06:17 AM
Make a page called whateveryoulike.php, stick the following in it:

<?php phpinfo(); ?>

You'll get a bunch of details on your servers php setup if you have php, if you don't then it won't work at all and you'll get a blank page with "<?php phpinfo(); ?>" written on it (because it's not parsed).

Gordo
08-26-2002, 06:20 AM
While you were typing that, I was checking with my web host server.

The web host that the site is currently on probably does support PHP. But, the site is scheduled to be moved to a new web host as soon as the redesign/recreation is complete. And the new host of choice does NOT support PHP. :mad:

joh6nn
08-26-2002, 06:33 AM
just do the same with javascript:

<iframe name="contents" src="default.htm" width="200px" height="300px"></iframe>

http://www.domain.com/services.htm?somepage.htm

<script>
window.onload = function() {
if (window.location.search) {
window.frames['iframe'].location = window.location.search.slice(1);
}
}
</script>

Gordo
08-26-2002, 09:16 AM
joh6nn...thanks for dropping by (again)!

I tried your code. I wasn't too sure in which page to place the <script> portion of code. So, I tried it in each of the three pages. I tried changing it to window.frames['content'].location = window.location.search.slice(1);. I tried every combination...every which way.

The main navigation link would open the services.html page, but just ignored the ?tax.html portion. the services.html and tax.html pages (for testing purposes, etc) are in the same folder.

Here are the three test pages in the most basic form. Maybe this'll help, maybe not. Hopefully, some of you can play with it (test it) and get it to work.

GENERIC-PAGE.HTML (without the IFRAME):
<head>
</head>
<body>
<p><a href="services/index.html">Services</a><br>
<a href="services/index_iframe_n4.html?tax.html">Tax Page To Be Targeted Into Services' IFRAME</a><br>
<a href="clients/index.html"></p>
</body>
</html>

SERVICES/INDEX.HTML
Services folder index page with IFRAME in it...have a blank page as the default IFRAME src:
<head>
</head>
<body>
<p>A listing of services would be linked here -- each being targeted into the IFRAME.</p>
<nolayer>
<iframe name="content" id="content" style="position:relative; width:100%; height:360" src="blank_page.html" scrolling="auto" frameborder="0"></iframe>
</nolayer>
</body>
</html>

SERVICES/TAX.HTML
This page is in the same SERVICES folder as the index.html. It's content is to be placed inside the IFRAME.
<head>
</head>
<body>
This is the tax page.
</body>
</html>

joh6nn
08-26-2002, 09:41 AM
services/index.html should have the following:

<script>
window.onload = function() {
if (window.location.search) {
window.frames['content'].location = window.location.search.slice(1);
}
}
</script>

check to make sure that there are no conflicting onload event handlers

Gordo
08-26-2002, 10:01 AM
You know, I actually thought to check for other ONLOAD events...but overlooked the only one...and (of course) it was in the services/index.html page.

(banging head against wall)

Now, I can take this other ONLOAD event and put it in the <head> using <script>, etc., but I'd rather keep it in the <body> tag. Maybe I'm tired, but the way around this is just not coming to me.

My other onload event is:
onload="if(document.layers){window.location='index_n4.html'}"
...redirecting N4 users to an alternate page sans the IFRAME, etc.

I'll work on it...unless you or someone posts a quick reply.

THANKS!!!!!!!!!!

joh6nn
08-26-2002, 10:04 AM
well, i'm not sure how to keep the two in the body tag, but here's the code for in the head:

<script>
window.onload = function() {
if(document.layers) {
window.location='index_n4.html';
}
if (window.location.search) {
window.frames['content'].location = window.location.search.slice(1);
}
}
</script>

joh6nn
08-26-2002, 10:22 AM
well, this is actually a worse way to do it than the window.onload = function() way, i think, but it should work:

<body onload="if(document.layers){window.location='index_n4.html'} else { if (window.location.search) { window.frames['content'].location = window.location.search.slice(1); } }">

Gordo
08-26-2002, 10:28 AM
Do the two onload events need to be tied together like that -- with the else/if??? Does it matter one way or another?

You know, I don't care too much about how ugly the code is or isn't....just as long as it works.

So, what's the best? My thought was that on the off chance an N4 user with JavaScript disabled came to the site, they'd at least reach the correct "services" page with the information links. That's my logic (flawed or not) for wanting it in the <body>. YOUR THOUGHTS?

I just changed it to this (as you were typing the last reply .... again) :D :

<script>
function loadiframe() {
if (window.location.search) {
window.frames['content'].location = window.location.search.slice(1);
}
}
</script>
</head>
<body onload="if(document.layers){window.location='index_n4.html'}; loadiframe()">

joh6nn
08-26-2002, 07:12 PM
if javascript is disabled, then no matter where the code is, it's not going to execute. except for that one problem, the way you set it up should work fine.

Gordo
08-27-2002, 03:01 AM
Yeah, I never really thought about it too much. The number of folks who DO have JavaScript turned off can just ... well ... let's just say I'm not going to lose any sleep over them.

Your help is GREATLY appreciated -- as always!!!

What comes around goes around -- your karma bank account is full my friend!

Okay...off to put in the content on the main pages...and make any requested edits. Hopefully I'll have this project done soon enough, and can move onto bigger and better things.

One last note...you charge WAY too little! $12/hr!? That's unreal. But, your clients are more than pleased I'm sure.