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 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Making external website target iframe. Some help please.

    Hello. I have built a basic website that contains an iframe in the middle, called "iframe1". In this iframe I wish to load an external message board from proboards.com. In my code I can easily do this by making a button or hyper-link with the href="httproboards.com/myforums" and the target="iframe1"

    When I do this it will load inside of it the iframe jsut as I want it to. However, my the problem is when you click on the button to login its coded to target "_top" and it opens on the entire page replacing the whole website. If i run firebug (a real time HTML editor). I can easily locate and change the link code to target="iframe1". But How can I write a script in javascript in my webpage code to do this as soon as the iframe has loaded the external messageboard?

    I have also been trying things like
    javascript:void(document.iframe1.getElementsByTag("a")[5].target="iframe1")

    but i have had no luck so far in changing the target without the aid of firebug.

    Here is the code that needs to be changed. the target="_top" needs to be altered somehow to target="iframe1" as soon as the frame has finished loading the messageboards.

    Code:
    <p><font size="2"> 
    
    Welcome Guest.  Please <a href="/index.cgi?action=login" target="_top">Login</a> or <a href="/index.cgi?action=register" target="_top">Register</a>.<br/>Nov 19, 2010, 7:23pm
    
    </font><br /></p>
    Heres a screenshot that may help, as you can see I have easily changed the target of the link to="iframe1" using firebug, but I need to hardcode a script in my website that does this automatically after the iframe has loaded the forums page.

    http://img191.imageshack.us/img191/7264/26796014.jpg

    Thanks to for any help.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,885
    Thanks
    79
    Thanked 4,421 Times in 4,386 Posts
    You can't. Period. End of discussion.

    You can never use JavaScript to modify--or even *read*--anything from any other site.

    Can't even do so using AJAX techniques.

    It's a MAJOR security feature in browsers--sometimes referred to as "same origin"--so don't expect to find a way around it.

    http://en.wikipedia.org/wiki/Same_origin_policy
    Last edited by Old Pedant; 11-20-2010 at 01:38 AM.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    You can't. Period. End of discussion.

    You can never use JavaScript to modify--or even *read*--anything from any other site.

    Can't even do so using AJAX techniques.

    It's a MAJOR security feature in browsers--sometimes referred to as "same origin"--so don't expect to find a way around it.
    No, but once the site is loaded locally on the client computer u can easily change elements via JavaScript or firebug. such as using the JavaScript:void command. So I am wondering if their is a way this can be automated with a script that loads when the frame on my site loads the external site to alter the local html file links to target my frame instead of _top. I know its possible because i already changed the target to work exactly the way i want it to with firebug. I just need to know how to automate this with a script after the client has been served the website.
    Last edited by jim447; 11-20-2010 at 01:40 AM.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,885
    Thanks
    79
    Thanked 4,421 Times in 4,386 Posts
    *SIGH* Modifying something ON YOUR MACHINE using Firebug is a *LOT* different than a browser doing something automatically.

    Firebug is *INTENDED* for use like this. Intended to allow developers to modify code, inspect values, etc. In any case, no longer is it JavaScript that is in control, it is *YOU* the human being. And if you want to do something to wipe out the hard drive on your computer, or supply your social security number to every site in the world, indeed you should be allowed to do so.

    But scripts loaded from the internet should *NEVER* be allowed to do this.

    Again:
    http://en.wikipedia.org/wiki/Same_origin_policy

    By the way, if YOU could do this, what is to stop every hacker site in the world from installing stuff on your computer that, for example, captures all your keystrokes and so knows your passwords and whatever else you type in?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    alrighty, thanks for the information sir. Now if I may rephrase my question. How can I contain an external website within an iframe indefinitely, using any given method, so that when any link is clicked the external site always loads within the frame?

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,885
    Thanks
    79
    Thanked 4,421 Times in 4,386 Posts
    Same answer. You can't.

    If you could, don't you think thousands of other sites would be doing the same thing you are trying to do.

    If a site refuses to be framed, it can do so. Simple as that.

    You could turn off JavaScript. That would probably stop sites from popping to the top as soon as they load. But all anybody has to do is create a link such as
    Code:
    <a target="_top" href="whatever...">
    or a form such as
    Code:
    <form target="_top" action="whatever...">
    and zap, out of the iframe as soon as the link is clicked on or the form submitted.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    jim447 (11-20-2010)


  •  

    Posting Permissions

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