Twitter BootStrap Modal Window fallback link

旧巷老猫 提交于 2019-12-03 11:59:58

Looking at line 223 in bootstrap-modal.js revealed what's happening:

, option = $target.data('modal') ? 'toggle' : $.extend({ remote:!/#/.test(href) && href }, $target.data(), $this.data())

When using the data api the modal checks if the href attribute is not an id and sets that as the value for the remote option. This causes the page to load the data-target content initially and then load in the href content after as remote content.

So to avoid the href content getting loaded into the modal you need to specify data-remote="false" on your link:

<a href="/some-login-page.html" data-toggle="modal" data-target="#login-modal" data-remote="false">Login</a>

The Modal plugin gives precedence to the data-target attribute. You can then use the href to point to the fallback link that you want. Since the Modal plugin calls preventDefault on click events matching the selector [data-toggle="modal"], the link will only be followed if JavaScript is disabled (or the Modal plugin isn't loaded).

One thing to keep in mind, however, is that the Modal plugin does use the href attribute for loading remote content. To bypass that feature from being activated, just include a '#' at the end of the href value.

<a href="/some-login-page.html#" data-toggle="modal" data-target="#login-modal">Login</a>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!