[英]use an anchor/link element to open a particular page, and automatically open a modal on that page
I have both login and registration modals on my home page. 我的主页上同时具有登录和注册模式。 These exist on a element which is present on all pages.
这些存在于所有页面上存在的元素上。 I would like to set the anchor elements for login/registration on the non-home pages to open the home page with the modal to automatically open.
我想在非主页上设置用于登录/注册的锚元素,以使用自动打开的模式打开主页。
By default there display property is set to none when you open the page, I just wanted to create links to these pages and automatically open the modals? 默认情况下,当您打开页面时,display属性设置为none,我只想创建指向这些页面的链接并自动打开模式? Is there a way to use JS to do this?
有没有办法使用JS来做到这一点?
Any know how would be grand, thank you. 知道会怎么样,谢谢。
The JavaScript way: inspect the URL using window.location
for something that indicates which modal should open (eg ?modal=login
), and open that modal. JavaScript方式:使用
window.location
检查URL,以指示应打开哪个模式(例如?modal=login
),然后打开该模式。
The CSS way: if each modal has a unique ID, you could use the :target
pseudo-class to apply display: block;
CSS方式:如果每个模式都有唯一的ID,则可以使用
:target
伪类来应用display: block;
(or whatever) to the element when indicated in the URL fragment (so your link would have #login
or #registration
at the end). (或其他内容)在URL片段中指示时(因此,链接的末尾将具有
#login
或#registration
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.