0

I'm trying to redirect my window in base a value of button but i can get work

this is my code

<!DOCTYPE html>
<html>
<body>
  <p>Click the button to change the location of the first iframe element (index 0).</p>

  <button class="godd" onclick="myFunction()">Try it</button>
  <br>
  <br>

  <iframe src="http://localhost:8005/?xform=http://127.0.0.1:8080/output_path4fff"></iframe>
  <iframe src="http://localhost:8005/?xform=http://127.0.0.1:8080/output_path4fff"></iframe>

  <script src="http://code.jquery.com/jquery-1.11.0.min.js">
    $(document).ready(myFunction() {
      var Vp = $('.godd').eq(0).text();
      window.frames[0].top.location.href = 'http://' + Vp;
    })
  </script>
</body>
</html>

please help

1

3 Answers 3

3

Jquery Code should be like following:

function myFunction()   {  /* myfunction declaration */
  var Vp = $('.godd').eq(0).text();  
  window.frames[0].top.location.href  = 'http://' + Vp ;
};
$(document).ready(function(){  /* DOM ready callback */

});

You should define your function outside DOM ready. Read $(document).ready

Your script tag should be like this:

<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script>
    //Jquery Code
</script>
Sign up to request clarification or add additional context in comments.

Comments

2

please call function on page ready below code. please check it once:

<script>
function myFunction(){ 
      var Vp = $('.godd').eq(0).text();  
      window.frames[0].top.location.href  = 'http://' + Vp ;
}

$(document).ready(function(){ 
   myFunction();
});
</script>

Comments

2

script elements can have a src attribute or content, but not both. If they have both, the content is ignored (the content is considered "script documentation," not code).

Use another script block for your jQuery script

<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
</script>
<script>
    function myFunction()   { 
    }
</script>

You need to define the function in Global scope as you accessing it using inline click handler.

function myFunction()   { 
    var Vp = $('.godd').eq(0).text();  
    window.frames[0].top.location.href  = 'http://' + Vp ;
};
$(document).ready(function(){  
   // DOM ready callback         
});

However I would recommend should use unobtrusive event handler instead of inline click handler.

$(document).ready(function(){  
   $('.godd').on('click', function()   {  
      var Vp = $(this).text();  //Current element context
      window.frames[0].top.location.href  = 'http://' + Vp ;
   });
});

HTML

<button class="godd">Try it</button>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.