How can I email links to a modal on my webpage? - modal-dialog

Basically, I want to be able to send a link in email that links to my website that when clicked, it opens the site and the modal I added to the link. In other words, how can I send a link that will open the modal automatically?
here is my modal I want to open:
<div id="modal-video11" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title" align="center">State of the Table Grape Industry with Barry Bedwell</h4>
</div>
<div class="modal-body">
<div class="videoWrapper">
<p align="center"><iframe width="420" height="315" src="https://www.youtube.com/embed/PYq5hi5Y9rI" frameborder="0" allowfullscreen></iframe></p>
</div>
</div>
<div class="modal-footer">
<a class="btn btn-pnp center-block" href="https://www.youtube.com/user/CaliforniaAgNet">View MORE Videos On Our Youtube Channel!</a>
</div>
</div>
</div>
</div>
why can't I link it like this? : http://www.americanvineyardmagazine.com/index.html#modal-video11
I also tried using this javascript at the end of my page but it made no difference. The modal doesn't open:
<script type="text/javascript">
$(document).ready(function() {
if(window.location.href.indexOf('#modal-video11') != -1) {
$('#modal-video11').modal('show');
}
});</script>

Try this out:
jQuery(function($){
$(document).ready(function() {
if(window.location.href.indexOf('#modal-video11') != -1) {
$('#modal-video11').modal('show');
}
});
});

The code you are posting is correct, but there is a javascript error in that page. You are trying to use jquery ($) in line 143 before loading jquery (line 2001).
If you put that code after loading jquery (at the end), it should work.
<script type="text/javascript">
$(document).ready(function() {
if(window.location.href.indexOf('#modal-video11') != -1) {
$('#modal-video11').modal('show');
}
});
</script>

Related

displaying same div on click side by side and limit it to screen width with latest click first

i am new in web development. i have data(username) appearing on website. Now, i want to make popups, chat boxes just like facebook. each username has different div id. I already have a div for chat box(msg_box). I need this div to show up side by side on each click at bottom of page . also latest clicked username appear first. thanks.
<script>
$(document).ready(function(){
$(".nameid").click(function() {
var text = $(this).text();
document.getElementById("bb").innerHTML=text;
});
});
</script>
/head>
<body>
<div class="container">
<div class="header">
</div>
<div class="leftblock">
</div>
<div class="chat_box" id="cb">
<div class="chat_head_left"></div>
<div class="chat_head_right"></div>
<div class="chat_head">Members</div>
<div class="chat_body">
<?php
for($i=1;$usernamee=mysqli_fetch_assoc($records); $i++)
{
echo "<div class='nameid' id='$i' <b>".$usernamee['username']."
</br>"."</b></div>";
}
?>
</div>
</div>
<div class="msg_box" style="right:290px">
<div id="bb" class="msg_head">
<div class="close">x</div>
</div>
<div class="msg_wrap">
<div class="msg_body"></div>
<div class="msg_footer" ><textarea class="msg_input"
rows="4">sample</textarea></div>
</div>
</div>

Creating a modal box on page load

I want to insert this modal box on my webpage, but I don't have the css of this code:
http://www.bootply.com/testazoid/14LH4kZul2#
you'r might be looking for this
<body onload="myFunction()">
<h1>Hello World!</h1>
<script>
function myFunction() {
alert("Page is loaded");
}
</script>
</body>
</html>
This modal from bootstrap. you need bootstrap JS and CSS
refer this https://www.w3schools.com/bootstrap/tryit.asp?filename=trybs_modal&stacked=h
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script>
$(document).ready(function(){
$('#myModal').modal('show');
});
</script>
<div class="container">
<h2>Modal Example</h2>
<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p>Some text in the modal.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>

Modal button click required

How do i make my bootstrap-modal not to close when clicking outside the dialog box? since i want to force user to click a button on a modal.
below is an example of my modal from bootstrap
<!-- Approve Modal -->
<div class="modal fade alert-success" id="approvemodal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Approved!</h4>
</div>
<div class="modal-body">
<p>Return to vendor approved. </p>
</div>
<div class="modal-footer">
<button id="approvedone" type="button" class="btn btn-lg btn-success" data-dismiss="modal"><span class="glyphicon glyphicon-ok"> Done</button>
</div>
</div>
</div>
</div>
Given below is modern way of doing it. You can refer this link for further details of the way of creating modal dynamically.
function open_modal() {
BootstrapDialog.show({
title: 'Approved!',
message: 'Return to vendor approved.',
closeByBackdrop: false,
closeByKeyboard: false,
buttons: [{
label: '<span class="glyphicon glyphicon-ok"> Done',
action: function(dialog) {
dialog.close();
}
}]
});
}
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap3-dialog/1.34.7/css/bootstrap-dialog.min.css">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap3-dialog/1.34.7/js/bootstrap-dialog.min.js"></script>
<button onclick="open_modal()" type="button"> Open dialog</button>

How to pass links to modal triggered by multiple buttons in bootstrap?

I tried the following code found online to trigger one bootstrap modal with multiple buttons.
<script type="text/javascript">
$(document).ready(function(){
$("#myModal").on('show.bs.modal', function(event){
var button = $(event.relatedTarget);
var titleData = button.data('title');
var kbtext = button.data('whatever');
$(this).find('.modal-title').text(titleData);
$(this).find('.modal-body').text(kbtext);
});
});
</script>
HTML:
<div class="bs-example">
<!-- Button HTML (to Trigger Modal) -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal"
data-whatever="test 1" data-title="Test1">Test 1</button>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal"
data-whatever=' Click here'
data-title="Test2">Test 2</button>
<!-- Modal HTML -->
<div id="myModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header" style="text-align:center;">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
<h4 class="modal-title">Modal Window</h4>
</div>
<div class="modal-body">
Test body of modal.
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary">Send</button>
</div>
</div>
</div>
</div>
The problem is that the modal does not properly display the link in Test 2 button. I tried all types of combinations of quotes and escape codes for quotes that I could think of. Nothing worked. What quotes should I use for data-whatever for the second button, that is for
data-whatever=' Click here'
In particular, the following did not work
data-whatever=" Click here"
In second button you have HTML content data-whatever=' Click here' but you are handling it as .text();
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal" data-whatever=' Click here' data-title="Test2">Test 2</button>
In script just change this .text(kbtext);
$(this).find('.modal-body').text(kbtext);
to this .html(kbtext);
$(this).find('.modal-body').html(kbtext);
You are passing HTML content as text so that's why the link was showing like below in modal body
Click <a href='https://www.math.washington.edu'>here</a>
but you want to show content as HTML then use .html(); method more information and link will show like below in modal body
Click here
so second button will be like
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal" data-whatever="Click <a href='https://www.math.washington.edu'>here</a>" data-title="Test2">Test 2</button>
and Script
<script type="text/javascript">
$(document).ready(function(){
$("#myModal").on('show.bs.modal', function(event){
var button = $(event.relatedTarget);
var titleData = button.data('title');
var kbtext = button.data('whatever');
$(this).find('.modal-title').text(titleData);
$(this).find('.modal-body').html(kbtext);
});
});
</script>
Fiddle Example

bootstrap 3 modal in meteor not showing

I'm trying to get a bootstrap 3 modal to pop in a meteor app without any success at all. Everything seems to be in place, I've scoured here and else where and it simply won't work.
The HTML is
<!-- A modal that contains the bigger view of the image selected -->
<template name="projectImageModal">
<div class="modal fade in show" id="projectImageModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<p> Hi There</p>
<div class="modal-dialog">
<div class="modal-content">
<p> Hi There again</p>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Big Image</h4>
</div>
<div class="modal-body">
<img src="{{cfsFileUrl 'bigProjectImage' file=image}}" alt="..." class="img-rounded">
</div>
</div>
</div>
</div>
</template>
Which is triggered from a click event on an image thumbnail (which is working according to console.log
The code trying to show the dialog is
Template.projectImageItem.events = {
"click .open-modal" : function(e,t) {
e.preventDefault();
Session.set("selectedImageId", t.data._id);
console.log("Image ID: "+ Session.get("selectedImageId"));
//var stuff=$('#projectImageModal');
//console.log(stuff);
//stuff.modal('show');
// $('#projectImageModal').modal().modal("show");
$("#projectImageModal").modal("show");
//$('#projectImageModal').modal('show');
//$('.projectImageModal').modal('show');
}
};
Which is largely pulled directly from the cfs-file-handler example (which doesn't used bootstrap and calls the modal().modal("show") version to get the modal to pop).
You can see the variations I've tried. The console shows that the event is fired, the selector seems to be working but.. the modal NEVER pops.
Thanks. Peter.
I have tried the code below and it works as expected. If I add show to class="modal fade in" the modal immediately appears. If in your case it doesn't you are probably missing something else that is not shown in the sample code.
HTML
<head>
<title>modal</title>
</head>
<body>
{{> projectImageItem}}
{{> projectImageModal}}
</body>
<!-- A modal that contains the bigger view of the image selected -->
<template name="projectImageModal">
<div class="modal fade in" id="projectImageModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Big Image</h4>
</div>
<div class="modal-body">
<img src="{{cfsFileUrl 'bigProjectImage' file=image}}" alt="..." class="img-rounded">
</div>
</div>
</div>
</div>
</template>
<template name="projectImageItem">
<input type="button" class="open-modal" value="Show modal." />
</template>
JS
if (Meteor.isClient) {
Template.projectImageItem.events = {
"click .open-modal" : function(e,t) {
e.preventDefault();
$("#projectImageModal").modal("show");
}
};
}