View Full Version : How to PREVENT opening in new window?
04-22-2008, 09:10 PM
Here's a problem I'm having. I got my HTML page. In this page I have an iframe. The iframe is linked up to a page that I don't have control over, but what I want is that when someone clicks on a link in this iframe, that it replaces the what's in the iframe instead of opening a new window.
Is this even possible considering that I don't have control over the code that's contained within the iframe? If I do a view source on the page, I can see that they're doing a "target = _blank" to have this link open in a new window. Is there anyway to prevent this from happening? Thanks.
04-22-2008, 09:23 PM
04-22-2008, 10:04 PM
Your window cannnot use a script to read anything in the window in the iframe, if it is from a different origin.
Script in an iframe can call a new window, or even window.top.replace your window-
so pick your remote content with some care.
04-22-2008, 10:22 PM
it is possible that this user is working in an environment where there are multiple servers comprising a single web domain (using virtual mappings etc) and that he/she does not have access to the code (or is not allowed to modify the code) of the page in question, in these circumstances, you can read/modify the contents of the iframe.
04-22-2008, 10:57 PM
Nope. It's not. The page is from another domain and changes depending on the link prior to arriving at the page. Basically, we have a job listing site. Some job listings are in-house listings, in which case we just take them to our job listing page.
However, other listings that come up are pulled from outside listing sites. When showing the listing, we show the listing stuff inside an iframe. However, when a person clicks on a link to actually apply for that job, the whole "target = _blank" opens up a new window for that link. What we want to be able to do is that when a person clicks on that link to apply for the job that the new window just replaces the contents of our iframe.
Is that even possible? Looks like I'm stuck, huh?
04-22-2008, 11:07 PM
if you have the capabilities to run asp or php, you can request the page from the server side.
check out listing 3, gives an example of the syntax you'd need in your asp page to be able to fetch the page.
you would then set the source of your iframe to the page you've made to pull in the data from the other site. then you can access the contents of your iframe programmatically because they were last processed by a server on the same domain as your present page.
04-23-2008, 03:43 PM
Cool. That sounds like it should work. I'll give it a try. Thanks again!
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.