2 回答

TA貢獻1848條經驗 獲得超6個贊
const encodeParams = window.encodeURIComponent(JSON.stringify(obj));
const params = JSON.parse(window.decodeURIComponent(encodeParams));
補充回答
let baseUrl =
'static/html/charting_library/static/tv-chart.e816a7a6edc9de3ed709.html';
let obj = {
localserver: 1,
widgetbar: {
datawindow: false,
details: false,
watchlist: false,
watchlist_settings: { default_symbols: [] },
},
drawingsAccess: { type: 'black', tools: [{ name: 'Regression Trend' }] },
timeFrames: [
{ text: '5Y', resolution: 'W', description: '5年', title: '5年' },
{ text: '1Y', resolution: 'D', description: '1年', title: '1年' },
{ text: '6M', resolution: '120', description: '6月', title: '6月' },
{ text: '3M', resolution: '60', description: '3月', title: '3月' },
{ text: '1M', resolution: '30', description: '1月', title: '1月' },
{ text: '5D', resolution: '5', description: '5日', title: '5日' },
{ text: '1D', resolution: '1', description: '1日', title: '1日' },
],
locale: 'zh',
customCSS: 'night.css',
debug: false,
timezone: 'Asia/Shanghai',
};
// 序列化對象為 JSON 字符串并使用 base64 編碼
this.chartUrl = `${baseUrl}#${btoa(encodeURIComponent(JSON.stringify(obj)))}`;
$('#chart_iframe').attr('src', this.chartUrl);
解析參數
const params = JSON.parse(
decodeURIComponent(
atob(
document
.querySelector('#chart_iframe')
.contentWindow.location.hash.substr(1)
)
)
);
console.log(params);
添加回答
舉報