javascript 从javascript函数打开Shadowbox

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6571936/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 21:08:32  来源:igfitidea点击:

Opening Shadowbox from javascript function

javascriptasp.netshadowbox

提问by e-on

I'm trying to open Shadowbox from within a radio button onclick event on a asp.net web form without success. I was initially opening it using a button click which worked fine, but now need to make sure it happens when the radio button option is selected. I then tried to click the button in javascript (button.click()), but that only worked in IE and Newer versions of firefox. So I have opted to use Shadowbox.open, but it is causing some issues. Here is my code:

我正在尝试从 asp.net 网络表单上的单选按钮 onclick 事件中打开 Shadowbox,但没有成功。我最初使用按钮单击打开它,效果很好,但现在需要确保在选择单选按钮选项时发生。然后我尝试单击 javascript (button.click()) 中的按钮,但这仅适用于 IE 和较新版本的 firefox。所以我选择使用Shadowbox.open,但它导致了一些问题。这是我的代码:

if (yes.checked == true)
    {            
        var url = 'http://localhost:52963/items.aspx';
        Shadowbox.open( { content:    url, 
                        type:        "iframe", 
                        title:         "sbTitle ", 
                        options:   {   initialHeight:350, 
                                        initialWidth:450, 
                                        loadingImage:"loading.gif", 
                                        handleUnsupported:  'link' 
                                    } 
                     }); 
    }

This just seems to bring up the overlay but doesn't open the web page inside it. Anyone know where I'm going wrong?

这似乎只是显示了叠加层,但没有打开其中的网页。有谁知道我哪里出错了?

回答by e-on

Apparently I needed to add a player as well as a type. So the amended code is this:

显然我需要添加一个播放器和一个类型。所以修改后的代码是这样的:

Shadowbox.open( { content:    url, 
                    type:        "iframe", 
                    player:      "iframe",
                    title:         "sbTitle ", 
                    options:   {   initialHeight:350, 
                                    initialWidth:450, 
                                    loadingImage:"loading.gif", 
                                    handleUnsupported:  'link' 
                                } 
                 }); 

回答by Monsters X

I had a lot of trouble with this, I tried firing click using .trigger('click') from jquery , but that didnt work in chrome (worked in firefox)

我遇到了很多麻烦,我尝试使用 jquery 中的 .trigger('click') 触发点击,但这在 chrome 中不起作用(在 firefox 中有效)

Turns out the answer is pretty simple, similar to e-on answer, but dialed down.

结果发现答案非常简单,类似于电子回复,但已拨下来。

Your images are in a normal shadowbox gallery

您的图像位于普通的影子库中

<div class="gallery">
  <a  href="/img1.jpg" rel="shadowbox[gallery1]" >
    <img id="Image0" src="/img1.jpg" />
  </a>
  <a  href="/img2.jpg" rel="shadowbox[gallery1]" >
    <img id="Image1" src="/img2.jpg" />
  </a>
</div>

Then your clickable link

然后你的可点击链接

<a href="#" class="galleryLauncher" gallery="gallery1">Click to view all images</a>

I wired up the clickable link via jquery in a document.ready call

我在 document.ready 调用中通过 jquery 连接了可点击链接

$('.galleryLauncher').click(function () {

 //gallery to launch
    var id = $(this).attr('gallery');

 //get the first item out of the cache
    var content = Shadowbox.cache[1].content;

 //default options object
    var options = {}; 

 //now we can open it
    Shadowbox.open({
        content: content,
        player: "img",
        gallery: id,
        options: options
    });

    return false;
});