Solved

IFRAME TARGET

Posted on 2004-10-14
13
2,262 Views
Last Modified: 2009-12-16
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
Comment
Question by:yourbudweiser
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
  • +1
13 Comments
 
LVL 4

Expert Comment

by:jcrumble
ID: 12310529
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
 
LVL 3

Author Comment

by:yourbudweiser
ID: 12320435
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
 
LVL 5

Expert Comment

by:Hammadian2
ID: 12329110
change the target name to the IFrame name
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:jcrumble
ID: 12338828
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
 
LVL 3

Author Comment

by:yourbudweiser
ID: 12338884
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
 
LVL 4

Expert Comment

by:dreamer007
ID: 12343686
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
 
LVL 3

Author Comment

by:yourbudweiser
ID: 12346908
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
 
LVL 4

Expert Comment

by:dreamer007
ID: 12349224
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
 
LVL 3

Author Comment

by:yourbudweiser
ID: 12349787
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
 
LVL 4

Expert Comment

by:dreamer007
ID: 12350048
No problems - nearly done. I'll be out for an hour, will complete upon return..sry for delay. :)
0
 
LVL 4

Accepted Solution

by:
dreamer007 earned 100 total points
ID: 12358042
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
 
LVL 3

Author Comment

by:yourbudweiser
ID: 12358141
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question