【问题标题】:Html inside script tags - width and height not recognized脚本标签内的 Html - 无法识别宽度和高度
【发布时间】:2015-12-21 04:33:10
【问题描述】:

我正在使用脚本在我的网站上显示来自 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>

【问题讨论】:

  • 你能在图片中显示吗?
  • 确保禁用任何弹出窗口阻止程序,这些阻止程序通常会强制新窗口进入选项卡。当然,这只对您的测试有所帮助。对任何可能禁用了弹出窗口的客户端计算机都没有帮助。

标签: javascript html width


【解决方案1】:

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

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

其中strUrl是要在新打开的窗口中加载的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>'

【讨论】:

    猜你喜欢
    • 2016-09-11
    • 2021-07-31
    • 1970-01-01
    • 2015-09-11
    • 1970-01-01
    • 2016-02-19
    • 2015-10-08
    • 2013-02-21
    • 1970-01-01
    相关资源
    最近更新 更多