Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2287
  • Last Modified:

IFRAME TARGET

I have a page with an iframe. In the iframe, when the user clicks a link, instead of the new page appearing in the iframe, surrounded by my graphics, the new page replaces the current page. This is becuase some of the links in the iframe have the target="_top" attribute. How can I prevent the links from clearing out my page without having to remove the target="_top" ?
0
yourbudweiser
Asked:
yourbudweiser
  • 5
  • 4
  • 2
  • +1
1 Solution
 
jcrumbleCommented:
Unfortunately it sounds like where you have target="_top" is exactly the code you need to change.  I know you probably don't want to hear that but as your message indicates that you don't want to remove the target="_top" but I think you will probably have to in order to get the functionality you desire.  Along those lines I have two suggestions.  The first (and simplest) is to try changing the target to something other than top.  Maybe try using parent in some places as opposed to top or targeting a specific frame name.  The second alternative is to use a server side scripting language to dynamically change your target.  I would say your environment and experience should determine the server-side language you would want to use.  You can find a number of freeware and shareware tool that do bulk changes across directories and subdirectories to help you make youe changes and test here : http://www.all4you.dk/FreewareWorld/links.php
and information on IFRAMEs/FRAMEs here: http://developer.irt.org/script/frame.htm

Hope that helps somewhat and Good Luck,
Jeff
0
 
yourbudweiserAuthor Commented:
Jeff, thanks for responding. I checked out the websites you suggested... The first one, there are alot of links but I couldn't find one that would help me with my problem. I also looked throught the second link and although it had lots of tips for framed pages, none of them related to iframes that are stored on other servers. If you could suggest some ideas for a server side script that would do what I need, I would love to hear it, Thanks again, YBW
0
 
Hammadian2Commented:
change the target name to the IFrame name
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
jcrumbleCommented:
yourbudweiser, is there any a possibility that we can get some code snipits of what you currently have in place, and an explaination of your environment (platform, webserver, etc) as well as a list of the server-side languages you are familiar with?  Something I probably should have mentioned above is that most of the rules that govern frames are the same rules you would apply to iframes (there are some exceptions), but for what you are trying to do it sounds like you simply need to change your target.  Here are a few additional links pertaining to iframes that might prove useful:

http://developer.irt.org/script/1347.htm
http://developer.irt.org/script/1268.htm
http://developer.irt.org/script/333.htm
http://developer.irt.org/script/1648.htm
http://developer.irt.org/script/853.htm
http://developer.irt.org/script/1318.htm

Is there a particular reason you need to keep the target='_top' in place in your existing pages other than the fact that it might prove painful to make changes across your entire site?  I'll be watching for your response.

Good Luck,
Jeff
0
 
yourbudweiserAuthor Commented:
Hi Jeff, thanks for responding.

The page in the iframe is actually on another server which I have no control over. In the iframe page are links with the target=_top. When clicked the links open in a new window, outside of the iframe.

I cannot modify that page so I can't remove the target=_top and I can't modify it at all. Therefore, I need some other way to prevent the links target=_top from opening in a new window.

<iframe name="metro" src="http://metrotag.clickprint.com" height="600" width="820" border="0" frameborder="0"></iframe>

The web server is MS and I am familiar with ASP.

I'll be looking at the links you suggested also.

Thanks again,.
0
 
dreamer007Commented:
Hi,

This is funny, (well it is if you have PHP on your server).

frame.html
=======

<HTML>...
<iframe width="100%" height="100%" name="wibble" src="demo.php?url=http://metrotag.clickprint.com/"></iframe>
...</HTML>


demo.php:
=======

<HTML>...
<?php
if (eregi("http://metrotag.clickprint.com/", $url))
{ echo "<!-- from the site -->"; }
else
{
echo "<BASE href=$url>";
}
$html = implode ('', file ($url));
$html= str_replace ("target=\"_top\"", " ", $html);
$html= str_replace ("href=\"", "href=\"demo.php?url=", $html);
echo $html
?>
...</HTML>


Lol, it breaks on the 'design online' flash detection with an invalid session, but it's fun until then.... If this were specifically for this site, we could get around that.. but, anyway - just for kicks.

If you have PHP on the server and it's just for this site, let me know which items break and we'll correct them. If it's to frame any site, this is probably not the answer..(especially if no PHP)...

Well, it was fun.. ;)


0
 
yourbudweiserAuthor Commented:
Hey dreamer, thanks for responding but i'm not into PHP so... can you do something similar in ASP? What is your trying to do there?
0
 
dreamer007Commented:
I'll have a play with it. I'm all on linux hosting and although theres a versoin of asp, it's just not 100%, so testing is a bit diff...

Here is the version - http://www.thisisyourname.com/demo/test.php

Have a look.

We take in the webpage as a string, parse it and change the target. It's then displayed on our own dynamic page and...well, it works. lol.

Hmm, *thinking of test environment for asp witout messing too much with IIS....*

d.
0
 
yourbudweiserAuthor Commented:
dreamer, that works great! now if I can get it to work with ASP i'll be in your debt!

I'll work with it as well and looking foward to seeing your solution in ASP :-)

YourBudWeiser
Election 2004 Battleground State of Florida
0
 
dreamer007Commented:
No problems - nearly done. I'll be out for an hour, will complete upon return..sry for delay. :)
0
 
dreamer007Commented:
Ok, all is done - sry again for the delay. Found some space..

http://n.1asphost.com/dreamer007/demo/test.asp

The code is on the page. Just remove the space from the asp < % and % > delimiters when you paste it - 2 files test.asp and test2.asp. You should be ok customising this yourself... ; )

Whew! ASP, huh - why use one line in PHP when you can use 20, lol!

0
 
yourbudweiserAuthor Commented:
Hey dreamer, great job!

This problem was on my mind all day yesterday! With your help, I came up with the following last night:

page1.asp:
<iframe name="metro" src="includes/page2.asp?url=http://metrotag.clickprint.com/"></iframe>

page2.asp:
<%
Function GetHTML(strURL)
  Dim objXMLHTTP, strReturn
  Set objXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")
 
  objXMLHTTP.Open "GET", strURL, False
  objXMLHTTP.Send

  strReturn = objXMLHTTP.responseText
  Set objXMLHTTP = Nothing

  GetHTML = strReturn
End Function

newhtml = GetHTML(Request("url"))
newhtml = replace(newhtml, "target=""_top""", "")
newhtml = replace(newhtml, "href=""", "href=""page2.asp?url=")

response.write newhtml
%>

Thanks alot for sticking with this question, you were a great help!

YourBudWeiser
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 5
  • 4
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now