Плагин JQuery DynaTree - как вызвать гиперссылку
У меня есть ссылка на веб-странице
<li data="url: 'www.mypage.com?index.php?CId=2&MId=14&MTId=1'">mylink
В моем сценарии JS у меня есть
$(document).ready(function() {
$("#tree").dynatree({
persist: true,
onPostInit: function(isReloading, isError) {
this.reactivate();
},
onActivate: function(dtnode) {
var isInitializing = dtnode.tree.isInitializing();
var isReloading = dtnode.tree.isReloading();
var isUserEvent = dtnode.tree.isUserEvent();
if( dtnode.data.url )
window.open(dtnode.data.url);
}
});
});
Что мне делать вместо window.open
таким образом, URL перезагружается в том же окне, не открывая новое? Там нет имени на веб-странице, где я мог бы использовать способ iFrame.
4 ответа
Я бы предложил
onActivate: function(node) {
if( node.data.href ){
// use href to change the current frame:
window.location.href = node.data.href;
// or load data into a div tag:
// $("#div").load(node.data.href);
// or open href in another target frame:
// window.open(node.data.href, node.data.target);
}
}
Смотрите также здесь для другого примера: Как сделать гиперссылки в плагине dynaTree jQuery кликабельны?
Теперь dynatree позволяет размещать теги привязки в элементах li. Так что вы можете просто сделать:
<li><a href="www.mypage.com\index.php?CId=2&MId=14&MTId=1" target="_top">mylink</a>
Посмотрите примеры навигации здесь.
Это документированный способ:
onActivate: function(node) {
if( node.data.href ) {
window.open(node.data.href, node.data.target);
return false;
}
},
Вы пробовали это решение:
$(document).ready(function() {
$("#tree").dynatree({ persist: true,
onPostInit: function(isReloading, isError) { this.reactivate(); },
onActivate: function(dtnode) {
var isInitializing = dtnode.tree.isInitializing();
var isReloading = dtnode.tree.isReloading();
var isUserEvent = dtnode.tree.isUserEvent();
if( dtnode.data.url )
window.location.href = dtnode.data.url;
}
});
});