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

    Adding javascript to a webpage inside a iframe?

    Alright so I've been teaching myself php/javascript/html/joomla for the past couple weeks, learning as i go along. So bear with me if i seem like a total moron =p.

    I'm trying to run a script from a js file to add javascript to the website inside the iframe. I also would like the script to only be activated onclick(this is all in an article).

    To clarify my website has an iframe and this iframe contains a webpage from http://website987.com/. I want to run thescript.js on the website inside that iframe, to add javascript to that website, however i also only want to run this js file on the click of a link/button. I hope i'm being clear if I'm not please tell me and ill try to reiterate.

    I've been trying to get this to work for a while now and I feel like this is really simple and I'm asking a stupid question. However this is what I've got so far, currently this just redirects the iframe to the URL with my code on it(instead of actually running it).How could i edit this/what coding could I use to make it so thescript.js actually runs instead of it being just redirected?
    Reply With Quote

    Code:
    <?php
    $filename = 'thescript.js';
    $path = '/media/system/js/'; // add the path parameter if the path is different than : 'media/system/js/'
    JHTML::script($filename, $path, true); // MooTools will load if it is not already loaded
    ?>
    Code:
    <HTML>
    <HEAD>
    
    <script language="javascript">
    function loadOne()
    {
    parent.FRAME1.location.javascript: function('/media/system/js/thescript.js')
    }
    </script>
    </HEAD>
    <BODY>
    
    <iframe name="FRAME1" src="http://website987.com/" width="740" height="500" frameborder="0" scrolling="yes"></iframe>
    
    <a href="javascript:loadOne()">Click Here/a>
    </BODY>
    </HTML>
    Am i even on the right track? I've been testing out a billion different codes and I think it would be ridiculous to post them all so I was hoping someone could help me fix this code or at least point me in the right direction. I'm usually able to figure everything out on my own but I'm failing atm and I just need help on this one thing, I would be ever so thankful for any assistance provided, !

    (BTW I'm also currently using the Joomla CMS and a joomla plugin called CodeMirror that runs your code directly from the article, not sure if this is relevent or not)

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,310
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    For security reasons JavaScript cannot access anything beyond the domain of the current page. This is known as the "same origin policy" and prevents a document or script loaded from one origin from getting or setting properties of a document from a different origin.

    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

  • #3
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Sorry maybe I should clarify, this script(thescript.js) simpley allows users to stream an avi file from a download service in a divx player. I have this download service in a iframe and am trying to run this script on the click of a button to activate the streaming. Are you saying that running this script on a iframe is not possible?

    What if i instead ran the script data directly from my website instead of from an internal script would this change anything?

    Sorry once again, im a newbie and thanks for responding.


    Seeking intellectually weighted advice through volume often yields what your looking for.
    =)
    Last edited by Glitcher808; 12-07-2010 at 12:16 AM.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,652
    Thanks
    80
    Thanked 4,640 Times in 4,602 Posts
    You can change the ".src" of the <iframe>, from code in the page that contains it, but that is the *ONLY* thing you can change unless the domain that the <iframe> is loaded from is the same as the one the main page is loaded from.

    So you could do
    Code:
        document.frames["FRAME1"].src = "http://www.website487.com/somepage.html?run=thescript.js";
    And *IF* that page on that site understood that "command" it could then process your request to run that script.

    But once the page from the "foreign" site is loaded into the iframe, your page has NO control on its contents. And you can't even communicate further with it.
    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:

    Glitcher808 (12-07-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
    •