如何从URL加载动态jquery ui对话框?

时间:2022-03-23 19:38:37

I have a page which has a series of dynamic jquery ui dialogs which have different id's. For example:

我有一个页面,它有一系列动态jquery ui对话框,它们有不同的id。例如:

<div id="message-1">
content
</div>

<div id="message-2">
content
</div>

I want some code that can launch the appropriate dialog box based on URL.

我想要一些可以基于URL启动相应对话框的代码。

For example, if the url was http://url.com/#message-2 it would open only the appropriate dialog box.

例如,如果网址是http://url.com/#message-2,则只会打开相应的对话框。

I've been trying to use code like the following as a basis to start from, but it clearly isn't a solution.

我一直在尝试使用以下代码作为开始的基础,但它显然不是一个解决方案。

if(window.location.href.indexOf('#message') != -1) {
            $('.dialog').dialog('open');
}

Any help will be greatly appreciated.

任何帮助将不胜感激。

2 个解决方案

#1


1  

I think you are looking for this

我想你正在寻找这个

    $(window.location.hash).dialog('open');

#2


0  

Use window.location.hash to get the #message-part of the url.

使用window.location.hash获取url的#message-part。

if(window.location.hash == '#message-1') {
            $('.message-1').dialog('open');
}

This code works with #message-1, #message-2 ... #message-n

此代码适用于#message-1,#message-2 ...#message-n

if(window.location.hash != '') {
            $('.' + window.location.hash).dialog('open');
}

Note: You should probably validate input but i didn't since it's an example

注意:您应该验证输入,但我没有,因为它是一个例子

#1


1  

I think you are looking for this

我想你正在寻找这个

    $(window.location.hash).dialog('open');

#2


0  

Use window.location.hash to get the #message-part of the url.

使用window.location.hash获取url的#message-part。

if(window.location.hash == '#message-1') {
            $('.message-1').dialog('open');
}

This code works with #message-1, #message-2 ... #message-n

此代码适用于#message-1,#message-2 ...#message-n

if(window.location.hash != '') {
            $('.' + window.location.hash).dialog('open');
}

Note: You should probably validate input but i didn't since it's an example

注意:您应该验证输入,但我没有,因为它是一个例子