0
我怎樣才能讓這個更安全,更安全:從標題窗口打開
- 地帶不安全的字符
- 防止未定義的錯誤
到目前爲止的代碼:
// Open HREF in popup window
$('.external').bind('click', function() {
var url = $(this).attr("href");
var title = ($(this).attr("data-popup-title")) ? $(this).attr("data-popup-title") : $(this).attr("title");
var image = $(this).attr("data-popup-image");
var width = ($(this).attr("data-popup-width")) ? $(this).attr("data-popup-width") : '626';
var height = ($(this).attr("data-popup-height")) ? $(this).attr("data-popup-height") : '436';
window.open('http://www.facebook.com/sharer.php?s=100&p[title]=' + title + '&p[url]=' + url + '&&p[images][0]=' + image, 'sharer', 'toolbar=0,status=0,width='+width+',height='+height);
return false;
});
也是最佳做法return false
或使用preventDefault()
?
這不是安全。在JavaScript中剝離標籤中的數據沒有什麼安全的。如果有人設法將腳本注入鏈接的`title`屬性,他們就有能力在處理程序出現之前執行該代碼並打開一個彈出窗口。做你正在做的事實在沒有意義。此外,請僅爲每個問題發佈一個問題。 – meagar 2011-12-14 21:06:23