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!

Open in mainframe.

Status
Not open for further replies.

Halling

Programmer
Jul 2, 2003
15
SE
I have a script that prevents individual pages of my webpage to be opened outside my frames. It looks like this:

if (top.frames.length == 0) {top.location.href="/?" + self.location};

One problem with this is that it first loads the frameset with my welcome-page. First when the welcome-page has loaded completely it is replaced with the requested page.

How can I change the script so it doesn’t open the welcome-page first, but go directly to the requested page?

How do I complement the script to prevent my pages to be opened in frames of another website (deep-linking).
 
this thread: thread216-577858

shows how to make both a framebuster and prevent deep-linking. note it uses an iframe, so you may have to modify. you'll also need to modify the specific frame and document names ("sara", "index_main.html")

=========================================================
try { succeed(); } catch(E) { tryAgain(); }
-jeff
 
Thanks for the reply, but unfortunately I don’t use iframe, just “ordinary” frames. As I understand it Iframe is less supported by old browsers, so for the compability I will continue with the old frames.

Is there I way to adapt the script to ordinary frames? You write “put it in index”, but how can that work? You need to put some code on every page, right? Maybe I misunderstand everything because I have never used Iframe.

Conclusion; Still needs help! :)
 
what i mean by "put it in index" is to put the script in your index file or frameset file.

what you'll have to do depends on how your frameset is set up, but here's an example with two frames.
Code:
<script type=&quot;text/javascript&quot;>
//  the name of your frameset page
var sFrameset = &quot;index.html&quot;;

//  the name of your main content frame
var sMainframe = &quot;mainFrame&quot;;

//  the name of your main content frame default page
var sDefault = &quot;myDefaultPage.html&quot;;

window.onload = function(){ 
    if (parent.frames.length > 0) {
        if (parent != self) {
            var sPage = self.frames[sMainframe].location.href;
            parent.location.href = sFrameset + &quot;?&quot; + sPage;
        }
    }
}

var s = location.search.substring(1);
var src = s.length ? s : sDefault;

document.write('<frameset rows=&quot;75,*&quot;>');
document.write('<frame name=&quot;topFrame&quot; src=&quot;top.html&quot;/>');
document.write('<frame name=&quot;' + sMainframe + '&quot; src=&quot;' + src + '&quot;/>');
document.write('<\/frameset>');
</script>

you'd need to change the vars sFrameset, sMainframe and sDefault accordingly, as well as the other frame names/dimensions etc inside the write() statements


=========================================================
try { succeed(); } catch(E) { tryAgain(); }
-jeff
 
Sorry, but I still don’t understand… :-/
My file index.html looks like this:

---File index.html start---
<HTML>
<HEAD>
Some tags here...
</HEAD>

<FRAMESET cols=&quot;180,*&quot; FRAMEBORDER=0 BORDER=0 FRAMESPACING=0>
<FRAMESET rows=&quot;60,*&quot; FRAMEBORDER=0 BORDER=0 FRAMESPACING=0>
<FRAME SRC=&quot;tom.html&quot; SCROLLING=&quot;NO&quot; NORESIZE>
<FRAME SRC=&quot;meny.html&quot; NORESIZE>
</FRAMESET>
<FRAMESET rows=&quot;155,*&quot; FRAMEBORDER=0 BORDER=0 FRAMESPACING=0>
<FRAME SRC=&quot;logo.html&quot; SCROLLING=&quot;NO&quot; NORESIZE>
<FRAME SRC=&quot;vaelkommen.html&quot; NAME=&quot;main&quot; NORESIZE>
</FRAMESET>

<noframes>
<p>Sorry, frames needed</p>
</noframes>

</FRAMESET>
</HTML>
---File index.html end---

I guess I should put the code here? But if I type how can that page break out of alien frames and load into my frameset in the “main”-frame (i.e replace vaelkommen.html), only based on code in index.html?? I still think that I do need to put some code in page2.html!

I’m a bit confused…
 
this should do it:

<html>
<head>
<title></title>

<script type=&quot;text/javascript&quot;>
// the name of your frameset page
var sFrameset = &quot;index.html&quot;;

// the name of your main content frame
var sMainFrame = &quot;main&quot;;

// the name of your main content frame default page
var sDefault = &quot;vaelkommen.html&quot;;

window.onload = function(){
// if parent has frames...
if (parent.frames.length > 0) {
// ...but the parent is not this page...
if (parent != self) {
// ...get the currently displayed main frame page...
var sPage = self.frames[sMainFrame].location.href;
// ...and break out of the evil parent frame into our own
parent.location.href = sFrameset + &quot;?&quot; + sPage;
}
}
}

var s = location.search.substring(1);
var src = s.length ? s : sDefault;

document.write('<frameset cols=&quot;180,*&quot; frameborder=1 border=1 framespacing=0>');
document.write('<frameset rows=&quot;60,*&quot; frameborder=1 border=1 framespacing=0>');
document.write('<frame src=&quot;tom.html&quot; scrolling=&quot;no&quot; noresize>');
document.write('<frame src=&quot;meny.html&quot; noresize>');
document.write('</frameset>');
document.write('<frameset rows=&quot;155,*&quot; frameborder=1 border=1 framespacing=0>');
document.write('<frame src=&quot;logo.html&quot; scrolling=&quot;no&quot; noresize>');
document.write('<frame src=&quot;' + src + '&quot; name=&quot;main&quot; noresize>');
document.write('</frameset>');
document.write('<noframes>');
document.write('<p>Sorry, frames needed</p>');
document.write('</noframes>');
document.write('</frameset>');
</script>

</head>

</html>


and then put this in each of your content pages, to make sure they're always displayed in the frameset:

<script type=&quot;text/javascript&quot;>
if (parent == self) location.replace(&quot;index.html?&quot;+location.href);
</script>


=========================================================
try { succeed(); } catch(E) { tryAgain(); }
-jeff
 
this should do it - replace in each content page this:

<script type=&quot;text/javascript&quot;>
if (parent == self) location.replace(&quot;index.html?&quot;+location.href);
</script>

with this:

<script type=&quot;text/javascript&quot;>
// if page not opened in our frameset, do so
if (parent == self) location.replace(&quot;index.html?&quot;+location.href);

// if page is deep linked, open in our frameset
try {
// if parent is a different domain, this should fail...
if (parent.frames[0].src != &quot;tom.html&quot;) {
location.replace(&quot;index.html?&quot;+location.href);
}
} catch(E) {
// ...so this should execute
location.replace(&quot;index.html?&quot;+location.href);
}
</script>




=========================================================
try { succeed(); } catch(E) { tryAgain(); }
-jeff
 
Well, well. That didn’t work… :(
When typing the script goes into an eternal loop. The reason is that the expression “if(parent.frames[0].src != &quot;tom.html&quot;)” evaluates true.

I made an experiment by putting this code into page2.html:

-----------------------------------
<script type=&quot;text/javascript&quot;>
document.write(&quot;Script is alive&quot;);

if (parent == self) location.replace(&quot;index.html?&quot;+location.href);

if (parent.frames[0].src == &quot;tom.html&quot;) document.write(&quot;tom&quot;);
if (parent.frames[0].src == &quot;meny.html&quot;) document.write(&quot;meny&quot;);
if (parent.frames[0].src == &quot;index.html&quot;) document.write(&quot;index&quot;);
if (parent.frames[0].src == &quot;logo.html&quot;) document.write(&quot;logo&quot;);
if (parent.frames[0].src == &quot;vaelkommen.html&quot;) document.write(&quot;vaelkommen&quot;);

if (parent.frames[1].src == &quot;tom.html&quot;) document.write(&quot;tom&quot;);
if (parent.frames[1].src == &quot;meny.html&quot;) document.write(&quot;meny&quot;);
if (parent.frames[1].src == &quot;index.html&quot;) document.write(&quot;index&quot;);
if (parent.frames[1].src == &quot;logo.html&quot;) document.write(&quot;logo&quot;);
if (parent.frames[1].src == &quot;vaelkommen.html&quot;) document.write(&quot;vaelkommen&quot;);

if (parent.frames[2].src == &quot;tom.html&quot;) document.write(&quot;tom&quot;);
if (parent.frames[2].src == &quot;meny.html&quot;) document.write(&quot;meny&quot;);
if (parent.frames[2].src == &quot;index.html&quot;) document.write(&quot;index&quot;);
if (parent.frames[2].src == &quot;logo.html&quot;) document.write(&quot;logo&quot;);
if (parent.frames[2].src == &quot;vaelkommen.html&quot;) document.write(&quot;vaelkommen&quot;);
</script>
-----------------------------------

And then typed The page opened in my frameset like it should, but only the first text “script is alive” vas printed.
 
Got it working in Netscape now. Were some problems with old files in the cashe I think. Still don’t work in Opera, but I can live with that!

So I’m closing the lid on this problem now. Thanks A LOT for all help!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top