2017-04-25 69 views
1

我到目前爲止的代碼,把我送到某個網頁:

甜警報2和javascript:如何使一個甜蜜的警報按鈕,當按下

swal({ 
    title: 'Successfully Registered!', 
    text: "Do you want to go to the Log In page?", 
    type: 'success', 
    showCancelButton: true, 
    confirmButtonColor: '#3085d6', 
    cancelButtonColor: '#d33', 
    confirmButtonText: 'Yes, send me there!' 
    }, 
    function(){ 
     window.location.href= "http://example.com"; 
    } 
); 

出於某種原因,window.location.href是不工作,我試圖只使用location.href和if(isConfirm)等。
我該怎麼辦?
的jsfiddle:https://jsfiddle.net/2dz868kd/

+0

您應該將代碼上傳到[jsfiddle](https://jsfiddle.net/),以便用戶可以看到演示並可以在其中進行更改。 – Webinion

+0

我做了,謝謝你的建議。 –

回答

3

在這裏你去:

swal({ 
 
    title: 'Successfully Registered!', 
 
    text: 'Do you want to go to the Log In page?', 
 
    type: 'success', 
 
    showCancelButton: true, 
 
    confirmButtonColor: '#3085d6', 
 
    cancelButtonColor: '#d33', 
 
    confirmButtonText: 'Yes, send me there!' 
 
}).then(function(result) { 
 
    if (result.value) { 
 
    location.assign("https://jsfiddle.net") 
 
    } 
 
});
<script src="https://unpkg.com/[email protected]/dist/sweetalert2.all.js"></script>

SweetAlert2文檔:https://sweetalert2.github.io/

請注意,SweetAlert2和SweetAlert是兩個不同的項目。 SweetAlert2使用ES6 Promises。

+1

老兄,你不知道我有多愛你!我花了太多時間試圖弄清楚。 –