我正在尝试使用我自己的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任何想法= /? –