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=".11.0.min.js">
$(document).ready(myFunction() {
var Vp = $('.godd').eq(0).text();
window.frames[0].top.location.href = 'http://' + Vp;
})
</script>
</body>
</html>
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./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
Share Improve this question edited Jan 23, 2017 at 5:44 Satpal 133k13 gold badges167 silver badges170 bronze badges asked Jan 23, 2017 at 5:19 user7412219user7412219 1441 gold badge3 silver badges11 bronze badges 1- checkout this stackoverflow./questions/15171008/… – ricky Commented Jan 23, 2017 at 5:30
3 Answers
Reset to default 3Jquery 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./jquery-1.11.0.min.js"></script>
<script>
//Jquery Code
</script>
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>
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./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 remend 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>