你的問題是,你正試圖執行加載另一個頁面時頁面內的代碼。你不能這樣做(你可以在單頁應用程序中完成,但這是另一回事)。
在你someotherpage.php
你應該添加以下代碼:
$(window).load(function(){
introJs().addStep({
element:$('#ck-dashboard-pending-task')[0],
intro:'Here you can see the todo list',
position:'left'
}).setOption('scrollToElement', true).start();
});
而且你應該在你的頁面刪除您的這部分代碼: VAR測試=「someotherpage.php」;
/* onload of someotherpage.php, execute this introjs step */
$(test).load(function() {
if (window.location.href === test) {
/* unable to execute this */
introJs().addStep({
element: $('#ck-dashboard-pending-task')[0],
intro: 'Here you can see the todo list',
position: 'left'
}).setOption('scrollToElement', true).start();
}
});
編輯: 由於要求由OP,這裏有一個澄清: 在第一頁,你可以做這樣的事情:
if (something === true) {
/* Redirect to someotherpage.php */
window.location.href = "someotherpage.php?some_condition_you_want_to_check=1"
}
在someotherpage.php
:
$(window).load(function(){
$.urlParam = function(name){
var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
if (results==null){
return null;
}
else{
return results[1] || 0;
}
}
if($.urlParam('some_condition_you_want_to_check') !== null){
introJs().addStep({
element:$('#ck-dashboard-pending-task')[0],
intro:'Here you can see the todo list',
position:'left'
}).setOption('scrollToElement', true).start();
});
}
}
當然,我的代碼是一個未經測試,肯定有待改進的部分,但是這應該讓你知道你需要做什麼來實現你想要的東西。
一旦設置了window.location.href,它將停止執行JS。 – George