Welcome to WebmasterWorld Guest from 35.172.195.49

Forum Moderators: open

Message Too Old, No Replies

One site with two windows and links which call either

     
3:51 am on Oct 31, 2003 (gmt 0)

New User

10+ Year Member

joined:Oct 24, 2003
posts:4
votes: 0


I am web beginner, working on a site that has within the same site 2 separate sections (main site and knowledge base) which open in 2 different windows, but which have links in either segment to pages in the opposite window. Thus far, using coding from forum 91/536 I have managed a start:

A. From the main site I am able to open the knowledge base in a separate window with:
<a target="_CtrlWindow" href="knowledgebase.htm">knowledge base</a>

B. Then from the knowledge base I am able to open any specific page of the main site in the main window with:
<a href="/mainwindow.html" onclick="window.opener.location.href('specificpage.htm');return false;">Specific Page</a>

The only problems are:

1.If the main window is hidden behind the knowledgebase window (normal), when the link in the knowledge base to the main site (B. above) is clicked, the page changes correctly in the main window, but the window still remains hidden behind.
2.If I open the knowledge base first with the main site closed, and try to use the same link in the knowledgebase (B. above) to open a page in the mainsite window I get an error.

Any help in resolving this would be much appreciated.

Kirk

6:10 am on Oct 31, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 26, 2003
posts:881
votes: 0


Hi Kirk,

Welcome to WebmasterWorld

1.If the main window is hidden behind the knowledgebase window (normal), when the link in the knowledge base to the main site (B. above) is clicked, the page changes correctly in the main window, but the window still remains hidden behind.

This one is pretty easy, you just need to use the focus() method to bring the main window into view.

Add this in the head of the knowledgebase document...

<script type="text/javascript"> 
<!--
function openInMain(url) {
if (window.opener) {
window.opener.location.href = url;
window.opener.focus();
}
return false;
}
//-->
</script>

Then make B. links like this...

<a href="specificpage.htm" onclick="return openInMain(this.href);">Specific Page</a>

This way the link will be visible by search engines (instead of them always seeing mainpage) because it has a real href.

2.If I open the knowledge base first with the main site closed, and try to use the same link in the knowledgebase (B. above) to open a page in the mainsite window I get an error.

This one is a bit tougher...the problem is that the winow.opener attribute is only set, and hence only accessible, when the window has been opened by JavaScript. so if you open the knowledgebase window yourself, all the window.opener references and assignments will fail with errors. I added in a check that will at least avoid the errors, but there isn't much you can do other than that. JavaScript is very selective about which windows you're allowed to tinker with (which is a good thing when you think about it); so unless there is some kind of established relationship like opener<->openee, JavaScript won't let you do a whole lot.

Jordan

9:54 am on Nov 1, 2003 (gmt 0)

New User

10+ Year Member

joined:Oct 24, 2003
posts:4
votes: 0


Jordan,

Thanks, that works!

Now, seems like it should be simple but nothing I've tried so far works: once I've followed my links back to the main site window if I click a link going back again to the knowledge base window it still isn't coming to the fore. Can you help me with the script for the A. links so the knowledge base window will "focus".

Thanks again,

Kirk

9:55 am on Nov 1, 2003 (gmt 0)

New User

10+ Year Member

joined:Oct 24, 2003
posts:4
votes: 0


Jordan,

Thanks, that works!

Now, seems like it should be simple but nothing I've tried so far works: once I've followed my links back to the main site window if I click a link going back again to the knowledge base window it still isn't coming to the fore. Can you help me with the script for the A. links so the knowledge base window will "focus".

Thanks again,

Kirk

12:10 am on Nov 2, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 26, 2003
posts:881
votes: 0


Hey Kirk,

Glad it worked. :)

You can do something similar over on the main page for the A links to the knowledgebase.

In the head of the main page...

<script type="text/javascript"> 
<!--
var kbWin = null;
function openInKB(url) {
if (!kbWin) {
kbWin = window.open(url, '_CtrlWindow', '');
}
else {
kbWin.location.href = url;
}
kbWin.focus();
return false;
}
//-->
</script>

Then make A. links like this...

<a target="_CtrlWindow" href="knowledgebase.htm" onclick="return openInKB(this.href);">knowledge base</a>

Jordan

8:11 am on Nov 3, 2003 (gmt 0)

New User

10+ Year Member

joined:Oct 24, 2003
posts:4
votes: 0


Jordan,

Excellent! Thank you.

Now, one more question: The page which really ties the mainsite and the knowledge base together is the Index, which contains numerous links to both windows. It is generated in a program intended for producing online help. The resulting Index page is a complex table that would be a pain to edit manually if there were many changes. So the Index needs to be republished whenever there are significant additions (the knowledge base will increase significantly and continually). But this help software has no way of automatically building Java Script into the code.

My thoughts regarding how to minimize the amount of manual work are:

The Index is part of the mainsite which has the fewest links—links which are unlikely to change much. So I would like to set the knowledge base window as the default target for the Index table’s links. Can this be done with something like

<base target="_CtrlWindow" onclick="return openInKB(this.href)>

I tried this, but get a new window that is blank. Ideally I would like it to recognize the links without having to manually insert the onclick code into every link (I suppose I can do this with “search and replace all”). Then I would need to manually set all the links to the mainsite window as “target=self”, which is a bit cumbersome, but doable. Any suggestions you have are welcome.

Also, can you envision a script for doing full text search that would bring up the resulting links in the correct window? (In my dreams . . .)

Thanks again,

Kirk