Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

passing variables to iframes

  • 30-01-2006 11:50pm
    #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,317 ✭✭✭✭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,317 ✭✭✭✭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