Skip navigation
Niceman22
Currently Being Moderated

Vote Script ( Java Script ) iframe problem

Feb 7, 2013 2:27 PM

Tags: #problem #java #script #iframe #( #) #vote

Ok guy's i'm new with "Javascript", i decide to make vote script for all user's in xtremetop100.com

So here we go:

 

i trying make javascript function that check every 1 sec if iframe url is correct

So that's mean when i finish voting on that url, the javascript function will notice that iframe url is changed so

after iframe url is changed ( by voting ), then it will be show me message " Thank u for vote ".

 

Here is unploaded script , but it doesn't work: http://crystal-dekaron.zxq.net/

<script type="text/javascript">

var sitefr = document.getElementById("inneriframe")

{if

(sitefr.contentWindow.location!="http://www.xtremetop100.com/dekaron" )

    {

    alert ("Thanks for vote!");

    window.location="http://www.google.com"

    }

    else

    {

    alert ("U didn't vote!");

    window.location="http://www.help.com"

    }

}

window.setInterval(check, 1000);

</script>

 

after 60 second's pass, vote will be disabled ( i made that function )

 

I tryed that scipt with "inneriframe", and it doesn't work, only shows alert after i load page, but i didn't vote and url didn't change

 
Replies
  • Currently Being Moderated
    Feb 7, 2013 3:04 PM   in reply to Niceman22

    This would be a waste of CPU.  Why not just have the form submit redirect the iframe?

     

    ^_^

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 8, 2013 7:34 AM   in reply to Niceman22

    window.setInterval(check, 1000);

    You need a function "check" otherwise there are nothing to call

     

    --

    Kenneth Kawamoto

    http://www.materiaprima.co.uk/

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 18, 2013 1:13 AM   in reply to Niceman22

    Hi Niceman22,

     

    The experts here will be able ot help you better if you provide more clarity on what you are trying to do. List down the steps one by one.

     

    Thanks,

    Preran

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 18, 2013 6:02 AM   in reply to Niceman22

    The code would be something like:

    var timeout;

     

    function check() {

            if(timeout != undefined) window.clearTimeout(timeout);

     

            if(document.getElementById("inneriframe").contentWindow.location.href == "http://www.xtremetop100.com/dekaron") {

                alert("Thanks for vote!");   

            } else {

                timeout = window.setTimeout(check(), 1000);

            }

    }

    Then you'd call it on body load:

    <body onLoad="check()">

    However in reality this would not work, because JavaScript is not allowed to access Window.location.href of an iFrame element due to the cross-domain security restrictions. Check the error it generates.

     

    So you may need to explore other ways.

     

    --

    Kenneth Kawamoto

    http://www.materiaprima.co.uk/

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 19, 2013 3:02 AM   in reply to Niceman22

    No, you cannot get the current URL of an iFrame with JavaScript - try it yourself.

     

    If the site has an API for the voting system then you can use it rather than embedding the whole site in your page.

     

    --

    Kenneth Kawamoto

    http://www.materiaprima.co.uk/

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points