在 url 中使用 # 打开模式 [英] Open modal with # in url

查看:13
本文介绍了在 url 中使用 # 打开模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于这个可能很愚蠢的问题,我很抱歉,但我只想在 url 中使用 # 打开模式.因此,如果我调用 www.domain.com/#modal1 ,它将打开已经弹出模式的页面.

Im sorry for this probably dumm question, but I want to simply open modals with # in the url. So if i call www.domain.com/#modal1 it will open the page with the modal poped-up already.

哦,我正在使用 jquery.

Oh Im using jquery.

谢谢!

推荐答案

很多应用框架(我偏向backbone) 使用某种路由器来完成此操作,但您可以通过检查 window.hash 并运行适当的函数来伪造自己的:

Many application frameworks (I'm partial to backbone) use some kind of router to accomplish this, but you could fake your own by checking window.hash and running an appropriate function:

function popModal() {
  // code to pop up modal dialog
}

var hash = window.location.hash;
if (hash.substring(1) == 'modal1') {
  popModal();
}

这篇关于在 url 中使用 # 打开模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆