脚本标记中的Html-无法识别宽度和高度

Html inside script tags - width and height not recognized

本文关键字:识别 高度 Html- 脚本      更新时间:2023-09-26

我正在使用脚本在我的网站上显示Instagram上的图片。脚本本身运行良好,但我对html代码有问题。

在脚本中,有一些html代码,这样当用户点击其中一张Instagram图片时,就会有一个指向该Instagram页面的链接,该链接应该会在一个新的弹出窗口中打开。我希望弹出窗口的宽度和高度为500像素。

使用下面的代码,每个链接都会在新的选项卡中打开,而不是在新的弹出窗口中。我想问题是由html标签引起的。我想我应该摆脱内部标签,但显然这不是解决方案。

我在这里错过了什么?

<script type="text/javascript">
        var userFeed = new Instafeed1({
            get: 'user',
            userId: 'my_user_id',
            accessToken:'my_access_token',
            limit:'50',
            resolution:'low_resolution',
            template: '<div class="instafeed"><div class="instafeed-image"><a href="{{link}}" onclick="return !window.open(this.href, ''width=500, height=500'')" target="_blank"><img src="{{image}}" /></a><div class="instafeed-text"><a href="{{link}}" onclick="return !window.open(this.href, ''width=500, height=500'')" target="_blank"> {{likes}} {{comments}}</a></div></div></div>'
        });
        userFeed.run();
    </script>
    <div id="instafeed1"></div>

window.open()接受3个参数:

window.open(strUrl, strWindowName, [strWindowFeatures]);

其中CCD_ 1是要在新打开的窗口中加载的url,strWindowName是新窗口的字符串名称,strWindowFeatures是以字符串形式列出新窗口功能的可选参数。

您没有为窗口名称提供参数,因此使您的窗口功能成为新窗口的名称,而不是窗口功能。

要解决您的问题,只需在对window.open():的调用中添加一个参数

template: '<div class="instafeed"><div class="instafeed-image"><a href="{{link}}" onclick="return !window.open(this.href, ''COOL_WINDOW_NAME'',''width=500, height=500'')" target="_blank"><img src="{{image}}" /></a><div class="instafeed-text"><a href="{{link}}" onclick="return !window.open(this.href, ''COOL_WINDOW_NAME'', ''width=500, height=500'')" target="_blank"> {{likes}} {{comments}}</a></div></div></div>'