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

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

问题描述

很抱歉这个可能是愚蠢的问题,但我想简单地在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();
}

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

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