Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Apr 2008
    Posts
    43
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Question How to PREVENT opening in new window?

    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.

  • #2
    Regular Coder mjlorbet's Avatar
    Join Date
    Jan 2008
    Location
    Milwaukee, WI
    Posts
    724
    Thanks
    8
    Thanked 96 Times in 95 Posts
    i suppose it comes down to the domain that the displayed content inside the iframe originates from. if it's on the same domain, then you can gain programmatic access to the iframe, locate the appropriate anchor and set the target via javascript.
    -Mike
    "Want me to precludify him, like some kind of dispatcherator?... Can do!" -Bender

  • #3
    Regular Coder
    Join Date
    Mar 2006
    Posts
    728
    Thanks
    35
    Thanked 132 Times in 123 Posts
    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.

  • Users who have thanked mrhoo for this post:

    hadoob024 (04-22-2008)

  • #4
    Regular Coder mjlorbet's Avatar
    Join Date
    Jan 2008
    Location
    Milwaukee, WI
    Posts
    724
    Thanks
    8
    Thanked 96 Times in 95 Posts
    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.

    in the case that you've just opened a site on a different domain in your iframe, then mrhoo is right. there is a way around this, however. if you implement an http proxy through server side logic on the server you do have access to, you can request the remote page from a local server side page and have your iframe render that content, followed by using javascript in your main page to modify the contents of the proxy-requested remote page. the hangup with this is that if the remote page was using relative paths to its resources, they would no longer be available, all the resources would have to be absolutely pathed in order for them to find their true origins, which you could also correct via javascript (but that would take some work).
    -Mike
    "Want me to precludify him, like some kind of dispatcherator?... Can do!" -Bender

  • Users who have thanked mjlorbet for this post:

    hadoob024 (04-22-2008)

  • #5
    New Coder
    Join Date
    Apr 2008
    Posts
    43
    Thanks
    5
    Thanked 0 Times in 0 Posts
    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?

  • #6
    Regular Coder mjlorbet's Avatar
    Join Date
    Jan 2008
    Location
    Milwaukee, WI
    Posts
    724
    Thanks
    8
    Thanked 96 Times in 95 Posts
    if you have the capabilities to run asp or php, you can request the page from the server side.
    http://dotnetslackers.com/columns/aj...SPNETAJAX.aspx
    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.
    -Mike
    "Want me to precludify him, like some kind of dispatcherator?... Can do!" -Bender

  • #7
    New Coder
    Join Date
    Apr 2008
    Posts
    43
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Cool. That sounds like it should work. I'll give it a try. Thanks again!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •