2588 次
3 に答える
2
デフォルトのイベントを防ぐ必要があります...そこを見てください:event.preventDefaultそのようなもの...
function runSomeJsonpCall(event) {
if (!event) var event = window.event;
if (event.preventDefault) {
event.preventDefault();
}else{
// IE
event.returnValue = false;
}
var script = document.createElement("script");
script.src = "http://jsonpurl.com?parameter1=" + "someparam";
document.body.appendChild(script);
// you should wait for jsonp loading
// here i use an ID to retreive the element but you can do your way ...
setTimeout("changeLocation('"+ document.getElementById('linkID').href +"')", 1000);
}
changeLocation(location) {
window.location.href = location;
}
個人的には、インラインonclick属性の使用は本当に好きではありません。addEventListenerまたはattachEventを使用します...これは優れた方法だと思います:)
于 2012-06-06T20:51:11.813 に答える
0
function runSomeJsonpCall(obj) {
//...
document.location=obj.getAttribute('href');
return false;
}
<a onclick="runSomeJsonpCall(self);" href="http://www.goherenext.com"> make this work </a>
また、href リンクの http:// に注意してください
于 2012-06-06T21:09:18.443 に答える
-1
試す:
<a onclick="runSomeJsonpCall();" href="#"> make this work </a>
と:
function runSomeJsonpCall() {
var script = document.createElement("script");
script.src = "http://jsonpurl.com?parameter1=" + "someparam";
document.body.appendChild(script);
window.location("www.goherenext.com");
}
于 2012-06-06T21:44:54.270 に答える