Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

passing variables to iframes

  • 31-01-2006 12:50AM
    #1
    Registered Users, Registered Users 2 Posts: 1,086 ✭✭✭


    I have a program (which I cannot alter) which automatically creates a php page allowing me to insert iframes on it in specific places. I want to access a variable (hidden) on that page from my iframe which is a url. However the form from which I am trying to retrieve the variable has no name (below)

    <form method="POST" action="something.php">
    <input type="hidden" name="purchaseurl" value="https://www.url.com"&gt;
    </form>


    Is there some way I can use parent.document.purchaseurl.value or somehow find the value of the 'purchaseurl' variable so I can use this url in my form in the iframe.

    Complicated?


Comments

  • Registered Users, Registered Users 2 Posts: 1,275 ✭✭✭bpmurray


    Does window.parent.document.forms[0].purchaserurl work?


  • Registered Users, Registered Users 2 Posts: 1,086 ✭✭✭Peter B


    Am currently trying

    var t = window.parent.document.forms[0].purchaserurl.value

    That failed so I then looked through the page and saw it was the second form so tried

    var t = window.parent.document.forms[1].purchaserurl.value

    Is there anyway I can look for the variable which is called purchaseurl in a form, not sure which one, on a parent page.

    Also not sure if it makes a difference but the parent page's form is not submitted. So what I am trying to do is get a hidden value from a form which is not submitted. Is that possible?


  • Registered Users, Registered Users 2 Posts: 2,934 ✭✭✭egan007


    You could try a javascript to print all the element names....
    something like

    for (var i=1; i<document.elements.length; i++) {
    alert document.diy.elements.type
    }

    once you have the name you are in business


  • Registered Users, Registered Users 2 Posts: 68,173 ✭✭✭✭seamus


    If the document in the iframe is not in the same domain as the parent document, you will probably get an "Access Denied" javascript error.


  • Registered Users, Registered Users 2 Posts: 1,086 ✭✭✭Peter B


    Both documents are in the same domain. However I still cannot access the parent document. Just trying to access the title of the containing document.

    Have tried loads of variations using parent and window.

    eg alert(window.parent.document.title); -> does not work
    alert(window.document.title); -> returns title of iframe page.
    alert(parent.window.document.title); -> does not work

    Any ideas?


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 1,086 ✭✭✭Peter B


    By the way, somehow managed to open the Java Console on Firefox and have many permission denied exceptions. Such as....


    Error: uncaught exception: Permission denied to get property HTMLDocument.title

    Why would permission be denied?


  • Registered Users, Registered Users 2 Posts: 68,173 ✭✭✭✭seamus


    Do you have access to make changes to the main document?

    A small workaround I've found is to add an element to the main document (I used an <input type="hidden"> element), give it an id and a value attribute. Then from the iframe, you can use parent.document.getElementById('doctitle').value to get the value of this element.

    I also had some limited success with parent.document.getElementsByTagName('title') but I couldn't find out how to get the text between the <title> tags.


Advertisement