【问题标题】:jquery open a new image link with code posted [duplicate]jquery打开一个带有代码的新图像链接[重复]
【发布时间】:2014-10-21 13:51:27
【问题描述】:
(function($){
    $(window).load(function(){
        if(jQuery.isFunction(jQuery.fn.prettyPhoto)) {
            $.prettyPhoto.open(
                "images/ad1.jpg", // Image to be opened
                "title",    // Title of the pop-up
                "desc."     // The description
            );
            setTimeout(function() {
                $.prettyPhoto.close();
            }, 10000); // autoclose after 10 seconds
        } else {
            console.log("PrettyPhoto is not defined."); // log this message
        }
    });
})(jQuery);

我需要一些帮助。我正在尝试制作要在新标签中打开的图像(ad1.jpg)链接网址。我该怎么做?我已经尝试了很多选择来完成这项工作。我可能把代码放错了,但我已经尝试过 window.open 和更多选项。任何帮助是极大的赞赏。谢谢!

【问题讨论】:

  • 您想在代码的哪个位置打开新标签页?
  • 此代码位于 index.html 文件的页脚中。当域启动时,代码会正确显示消息,但需要在单击时在新选项卡中打开 URL。
  • 您目前观察到什么行为(链接是否在同一个选项卡中打开?它不会在任何地方打开吗?)?相关的 HTML 是什么?
  • 图片加载正确,只需要点击图片链接到另一个标签中的URL。

标签: javascript jquery


【解决方案1】:

试试这个:

(function($){
    $(window).load(function(){
        if(jQuery.isFunction(jQuery.fn.prettyPhoto)) {
            $.prettyPhoto.open(
                "images/ad1.jpg", // Image to be opened
                "title",    // Title of the pop-up
                "desc."     // The description
            );
            $("#fullResImage").click(function() {
                window.open("url/goes/here");
            });
            setTimeout(function() {
                $.prettyPhoto.close();
            }, 10000); // autoclose after 10 seconds
        } else {
            console.log("PrettyPhoto is not defined."); // log this message
        }
    });
})(jQuery);

这假定显示图像的图像 ID 始终为 fullResImage。我在http://www.no-margin-for-errors.com/projects/prettyphoto-jquery-lightbox-clone/documentation 找到了该信息。

【讨论】:

  • 如果您查看脚本图像加载正常,我需要当您单击图像时它会在新选项卡中打开一个 URL
  • 类似var img = document.getElementById("#theImage"); img.onclick = function() { window.open("the/url/here"); } ?
  • $.prettyPhoto.open( "images/ad1.jpg", // Image to be opened "title", // Title of the pop-up "desc." // The description 脚本中完美运行,需要 images/ad1.jpg 点击加载另一个标签中的 URL。
  • 还有 window.open 我可能在脚本中错误地放置了它。有人可以将它放在脚本中,以便我可以尝试吗?谢谢我对 jquery 很陌生
  • 好的,我明白你现在在说什么了。您希望显示灯箱照片,并在单击时打开一个带有 URL 的新选项卡。对吗?
猜你喜欢
  • 2014-10-21
  • 1970-01-01
  • 2014-12-09
  • 1970-01-01
  • 2017-07-19
  • 1970-01-01
  • 2016-06-16
  • 1970-01-01
  • 2014-10-21
相关资源
最近更新 更多