Linking Directly To An Open Modal Window Through a URL?

安稳与你 提交于 2019-12-10 14:47:42

问题


I don't know much at all about coding so hopefully i worded the question correctly.

What I am trying to do is link a person to a specific modal window on another website. In this example, I will use the Menards weekly ad to show what I would like to do.

I would like to link somebody directly to the weekly flyer page with the modal window already open for a specific product such as the $74.99 5 Shelf Unit, which when selected opens this window (http://i.imgur.com/lntNUpK.png). This is the window that I would like to directly link to somebody.

Is there a way to modify the URL to make this possible? About all I know how to do is how to link to a specific page of the URL which would look like this /main/flyer.html?page=5

One other thing to mention is if you go to the website that provides the ads, Flipp, it does allow you to directly link to the window https://flipp.com/item/175356457-muscle-rack-5shelf-steel-unit

Thanks for any help!


回答1:


Yes it is possible with some javascript, it will look for #myModal on the url if it finds it, it will load the modal:

just put this at the end of your page:

$(document).ready(function() {

  if(window.location.href.indexOf('#myModal') != -1) {
    $('#myModal').modal('show');
  }

});

Now just use the following url:

http://www.mywebsite.com/page.html#myModal

*your modal must have an id:




回答2:


How about that?

function openModalOnHash() {
  if(window.location.hash) {
    var hash = window.location.hash.substring(1);
    $('#'+hash).modal('show');
  }
}

$(document).ready(function() {
  openModalOnHash()
});


来源:https://stackoverflow.com/questions/41971131/linking-directly-to-an-open-modal-window-through-a-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!