SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2007
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    iFrame and PHP or javascript

    I am posting this in the PHP forum but this maybe something done with javascript. If someone can point me in the right direction, I would appreciate it. I have an iframe. The iframe is an amazon store. I need to take the current url from the iframe and insert the link in a textfield. I do this with javascript but it doesn't work as expected. Also after a certain text string (says buy now) I need to put the dollar amount in another textfield. Is this better to do with php or javascript? I would prefer PHP since the system is PHP. Again any help would be appreciated

  2. #2
    SitePoint Addict bronze trophy vectorialpx's Avatar
    Join Date
    Dec 2012
    Location
    Bucharest
    Posts
    247
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    There is no need for PHP here. You only need javascript.
    Code:
    var frameSRC = document.getElementById("my_iFrame").src;
    Also after a certain text string (says buy now) I need to put the dollar amount in another textfield
    Where is the textfield? Is it into your iframe?
    Can you control it with javascript (is it on your server)?
    Be nice to nerds. Chances are you'll end up working for one - Bill Gates
    > photos | admin panel

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2007
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks and Yes, I used the document.getElementById("my_iFrame").src; and it works but if someone goes to a new page in the iframe it does ny get the new page. It just gets the original page.


    I can control the page with the text in the iframe.

  4. #4
    SitePoint Addict bronze trophy vectorialpx's Avatar
    Join Date
    Dec 2012
    Location
    Bucharest
    Posts
    247
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    It will only work on the same server (same domain).
    However, you can set the value of that field after the button click, without checking the iframe.
    Code:
    <a href="http://localhost/__tests/json.php" target="go">page json</a>
    <a href="http://localhost/__tests/image1.php" target="go">page image1</a><br />
    <input type="text" id="checkURL" style="width:300px" />
    <iframe name="go" id="go" style="width:300px;height:100px" src="http://localhost/__tests/json.php"></iframe>
    
    <script>
    function getIframeSrc() {
    	return document.getElementById('go').contentWindow.location.href;
    }
    function setTextfield() {
    	document.getElementById('checkURL').value = getIframeSrc();
    }
    setTextfield();
    setInterval(function(){
    	getIframeSrc();
    	setTextfield();
    }, 200);
    </script>
    Be nice to nerds. Chances are you'll end up working for one - Bill Gates
    > photos | admin panel


Tags for this Thread

Bookmarks

Posting Permissions

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