我正在嘗試使用我自己的css修改iframe
中的某些div類,並更改Twitter Block | Drupal 8的樣子。但是,我遇到了很多錯誤,例如$ is not a function
等....我認爲我的js
加載速度太快(在我的jquery.js
之前),但是,我檢查了元素,一切都應該工作。 (現在沒有錯誤)如何設計Drupal Twitter塊?
HTML
<iframe id="twitter-widget-0" class="twetter-timeline" >
<html>
<head></head>
<body>
<div class="timeline-Viewport">
<ol class="timeline-TweetList">
<li></li>
</ol>
</div>
</body>
</html>
</iframe>
注:我沒有對iframe
這不是我自己的代碼控制。
JS
(function ($, Drupal, drupalSettings) {
Drupal.behaviors.yourbehavior = {
attach: function (context, settings) {
$('iframe').load(function() {
$('#twitter-wwidget-0').contents().find("body")
.append($("<style type='text/css'> .timeline-Widget{color:red;} </style>"));
});
}
};
})(jQuery, Drupal, drupalSettings);
沒有錯誤,但它不工作...所以我不知道我做錯了。
更新: 我也試過這個代碼,但也沒有工作。
(function($) {
$(document).ready(function() {
console.log('hello');
$('#twitter-widget-0').css('width', '100px');
});
}(jQuery));
iframe的內容是否在您的域名或Twitter的? https://en.wikipedia.org/wiki/Same-origin_policy – ceejayoz
嗨@ceejayoz它是在我的域名..感謝提問 –
@ceejayoz任何想法= /? –