|
|
Subject:
HTML, Javascript - Remove Frame Script / Code
Category: Computers > Programming Asked by: jucasoma-ga List Price: $15.00 |
Posted:
03 Mar 2005 09:29 PST
Expires: 02 Apr 2005 09:29 PST Question ID: 484055 |
I need a code or script enabling my website visitors to remove the top frame of a framed page or open a new window with the contents and URL of the mainpage. The frameset consists two frames: topframe and mainframe. This is what I have so far, but it's not working: <a href="#" onclick="parent.location.href=parent.document.getElementById('mainFrame').href'; return false" target="_top">Hide Top Frame</a> This should work for either pages on my server or external websites. I want this to work like google does with images preview: Example: http://images.google.com/imgres?imgurl=http://www.atpm.com/7.01/new-york-ii/images/nyc-12.jpg&imgrefurl=http://www.atpm.com/7.01/new-york-ii/nyc-12.shtml&h=768&w=1024&sz=103&tbnid=gsHgBbRsfOQJ:&tbnh=112&tbnw=149&start=1&prev=/images%3Fq%3Dnyc%26hl%3Den%26lr%3D%26safe%3Doff%26rls%3DGGLC,GGLC:1969-53,GGLC:en%26sa%3DN On this example, when users click on "remove frame" link, the frame is removed and the original URL of the main window replaces the frameset. Thanks! | |
|
|
There is no answer at this time. |
|
Subject:
Re: HTML, Javascript - Remove Frame Script / Code
From: willcodeforfood-ga on 03 Mar 2005 14:48 PST |
I tested only on IE 6.0 running on XP with SP2 using these three pages: ============= begin frameset.htm <html> <frameset rows="200,*"> <frame src="top.htm"></frame> <frame src="bottom.htm"></frame> </frameset> </html> ============= end frameset.htm ============= begin top.htm <html> <body> Top Frame </body> </html> ============= end top.htm ============= begin bottom.htm <html> <body> Bottom Frame <br> <a href="javascript:top.document.location.href = document.location.href">1. remove top frame using JavaScript</a> <br> <a href="" target="_top" onClick="this.href=document.location.href">2. remove top frame using a link targeted to _top</a> <br> <form method="post" target="_top" onSubmit="this.action=document.location.href"> <input type="submit" value="3. remove top fame using form post"> </form> <br> <a href="bottom.htm" target="_top">4. use targeted link and put static URL in the HREF attribute</a> </body> </html> ============= end bottom.htm I've demonstrated four ways to accomplish your goal, some of which may be blocked by the security settings on a user's browser. They are numbered on the demo pages I've included here. The first method gives me a "blocked content" message on IE as I believe the browser is detecting a possible cross-site scripting (CSS) attack. If I don't allow IE to show the blocked content, the first link does nothing. Once I click to allow active content, the first link works. The second method causes the same "blocked content" warning in IE. If I click to allow blocked content then the second link works fine. If I don't allow the blocked content, the link still works but sends me to the default page (i.e. the onClick event does not fire and the href attribute remains empty). The third method does not cause IE to give a "blocked content" warning. None of the first three methods will work if the user has disabled JavaScript altogether. The fourth method requires that you dynamically script the HTML of the bottom page and embed the URL (bottom frame's src attribute) into the href attribute of the anchor tag. This method will work even if the user has disabled JavaScript. |
Subject:
Re: HTML, Javascript - Remove Frame Script / Code
From: jucasoma-ga on 03 Mar 2005 15:53 PST |
Your codes are pretty much the same posted on the URL suggested on the question clarification: [Clarification of Question by jucasoma-ga on 03 Mar 2005 09:32 PST I also tried the methods posted on this page, but none of these would work, so take a look: http://www.webmasterworld.com/forum91/301.htm] And they wouldn't work because I need to remove the top frame from within itself since the mainframe could be any external page, as specified in the question, so the code must be placed in the Top Frame, again, the mainframe could be any website, but in the original frameset is called mainframe for manipulating purposes. |
Subject:
Re: HTML, Javascript - Remove Frame Script / Code
From: willcodeforfood-ga on 03 Mar 2005 17:00 PST |
I think I understand better what you are trying to accomplish. Essentially, you cannot get the URL of the bottom frame or set the URL unless the subdomain and domain portions of the URL are currently the same as that of the two other frames. To do so would amount to a successful cross-site scripting attack. For example, your user could be logged into a bank in the bottom frame and their access token could be embedded into the URL. Your JavaScript code in the upper frame obtains the URL and posts that back to your site. You get the access token and can pretend to be that user. Naturally an alert host (especially a bank) should detect this by the IP changing, but you get the idea. Having said that, there are a couple ways to get close to what you are trying. 1. If you already know the URL that the bottom frame was sent to (i.e. you put it into the frame's src attribute) you can script that into the href attribute of an anchor tag in the HTML of the upper page. See example 1 in the new pages I've included. 2. If you cannot know the URL that the bottom frame is pointing to or the user may have navigated elsewhere and you don't want to 'un-navigate' them back to their original page, the best you can do is resize the frameset to hide your upper frame. See example 2 in the new pages I've included. This second method causes my IE browser to display a security warning and requires I click to allow blocked content before the link will work. ============= begin frameset.htm <html> <frameset rows="200,*"> <frame src="top.htm"></frame> <frame src="http://cnn.com/"></frame> </frameset> </html> ============= end frameset.htm ============= begin top.htm <html> <body> <a href="http://cnn.com/" target="_top">1. remove top</a> <br> <a href="javascript:parent.document.body.rows='0,*'">2. hide top</a> </body> </html> ============= end top.htm Maybe somebody else has a way to do it, but I'm highly doubtful. Naturally you could accomplish all this and more with an ActiveX control, but I strongly suspect you're not wanting to head down that path, as that would lead to the dark side. |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |