How to add an 'escape button' to a website in HTML? - html

I'm trying to add an "escape button" to a Domestic Abuse help site for an HTML project. I have the button, an image, and it works, but the problem is that you can click outside of the image and it triggers the button. I'm trying to find a way to contain the button activation to inside the picture, not outside of it.
<p id="escape" onclick="myFunction()">
<img src="quickescape.png">
</p>
<script>
function myFunction() {
// Get away right now
window.open("http://weather.com", "_newtab");
// Replace current site with another benign site
window.location.replace('http://google.com');
}
</script>
Here's a demo of what I'm encountering if it wasn't clear: https://imgur.com/a/5QepBU1
Do I need to use a map id? Any help would be greatly appreciated.

myFunction is activated when clicking where p tag is. If p tag has space then onClick event will be in space too. Giving myFunction event to img tag will not accept activating function on empty space.
<p id="escape" >
<img src="quickescape.png" onclick="myFunction()">
</p>
<script>
function myFunction() {
// Get away right now
window.open("http://weather.com", "_newtab");
// Replace current site with another benign site
window.location.replace('http://google.com');
}
</script>

Don’t wrap it in a ‘p’ tag (that is a block level element). Wrap it in an inline element, like an ‘a’ or ‘span’.

That is a very good idea. If I were you, I would use this example below so that the website's last url won't show up in the history section.
function quickEscape() {
window.location.replace('https://www.example.com')
}
button {
height: 50px;
width: 100px;
background-image: url('https://www.sciencemag.org/sites/default/files/styles/article_main_large/public/butterfly_16x9_0.jpg?itok=jZ3DYvGK');
background-position: center;
background-size: cover;
color: pink;
font-weight: bold;
font-size: 1.25em;
-webkit-text-stroke: white 1px;
outline: none;
border: pink solid 2px;
border-radius: 10px;
cursor: pointer;
}
<button onclick='quickEscape()'>Quick Escape</button>

Related

Need css/jquery help adding 'open in new tab' functionality to span tag inside anchor link

I've got as far on this as I can with my own knowledge and looking things up online.
I want to automatically (through jquery/css) add an icon after external links that will cause the link to open in a new tab. So the reader can click the anchor text to open the regular link, or click on the icon to open the link in a new tab.
So far I've gotten an icon in a span tag to appear after external links.
What I need is... probably jquery? that will cause any clicks on the icon (in a span tag, id="ext") to open in a new tab.
Here's the fiddle so far:
https://jsfiddle.net/christophera/c0byn9w8/32/
Goal - The regular link (anchor text) should open in the same window. Mousing over the icon needs to display "open in new tab" and that needs to be the result when the icon is clicked on.
Appreciate any help in getting this accomplished!
Chris
$('a:not([href^="https://google.com"]):not([href^="#"]):not([href^="/"])').addClass('external');
.external span:last-child {
width: 16px;
height: 16px;
display: inline-block;
vertical-align: bottom;
background-image: url('https://i.ibb.co/vvyC5JS/new-tab-60.png');
margin-left: 2px;
background-size: contain;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<p>
This is the link<span id="ext"></span> and some test text afterwards.
</p>
Set attribute target , _blank after add class like:
$lnk.attr("target", "_blank").next('span').addClass('external');
To click span to open link on new tab, find previous anchor tag and trigger click.
Example:
var $lnk = $('a:not([href^="https://rev.press"]):not([href^="#"]):not([href^="/"])')
$lnk.attr("target", "_blank").next('span').addClass('external');
$(".ext").on("click", function() {
$(this).prev('a')[0].click();
});
.external {
width: 16px;
height: 16px;
display: inline-block;
vertical-align: bottom;
background-image: url('https://rev.press/wp-content/uploads/2022/11/new-tab.svg');
margin-left: 6px;
background-size: contain;
cursor: pointer;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<p>
regular link <span class="ext"></span> and some test text afterwards.
internal link <span class="ext"></span> and some test text afterwards.
</p>
I slightly change your HTML and CSS, to give a class to span.
Note:
SO snippet don't allow to open new tab so Working Fiddle
id must be unique so use class.
After discussion on comment, updated answer.
var $lnk = $('a:not([href^="https://rev.press"]):not([href^="#"]):not([href^="/"])');
$.each($lnk, function(index, val) {
$(this).next('.ext').addClass('external').append("<a 'target'='_blank' href=" + val + " >")
});
$(".ext").on("click", function(e) {
var link = $(e.currentTarget).find('a');
var win = window.open(link.attr('href'), link.attr('target'));
});
.external {
width: 16px;
height: 16px;
display: inline-block;
vertical-align: bottom;
background-image: url('https://rev.press/wp-content/uploads/2022/11/new-tab.svg');
background-size: contain;
cursor: pointer;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<p>
Bing <span class="ext"></span> and an internal link <span class="ext"></span>.
</p>
<p>
Google <span class="ext"></span> and an <a href="https://rev.press/topic/news/">ininternal link
Updated Fiddle
First way
I think you can do something like this:
keep regular link in one anchor tag,
and in another anchor tag keep the same link but with target="_blank" attribute to open this link in new page, and inside tha anchor tag insert the image so that clicking on that icon opens the link in new page
<p>
regular link
<span id="ext"></span>
and some test text afterwards.
</p>
Check this: https://jsfiddle.net/dscmr6g7/1/

Size of a Link opening in a new tab

What is a custom HTML code for having a link (say abc123.com) which is of certain size and color and which opens in a new/blank tab.
Have tried blank standalone with link but need to know how to change the size and font color of the the link word "SUBMIT"
Ok, so what you need is to use the anchor tab which is In this to put the url is to use the href attribute and then the url. To chance the color and size and all of that would require you to have a class or id for the link. Then using CSS, you could format this link. use the color tag to change text color, and font-size to change the font size. For example, this is what I would do.
<style>
.link {
color: blue;
font-size: 30px;
}
</style>
Submit
Or, if that isn't what you want, you could try using a button and then an onclick function that opens a new link in a new tab. Try this code :
function submit() {
window.open('abc123.com');
}
<style>
.submit-button {
outline: none;
border: none;
background-color: transparent;
color: blue;
font-size: 40px;
}
.submit-button:hover {
text-decoration: underline;
}
</style>
<button class="submit-button" onclick="submit()">Submit</button>

How do you make a Div do the same thing as a a button?

I am trying to make a navigation bar for a project and I need a button to call the function for a dropdown menu. If I have a button, I can't format it the same as a div, and it stands out from the other options. Is there a way to make a div be a button? I have tried putting the onclick attribute on it, but then the drop-down menu doesn't appear in the same spot. Thanks in advance.
(I am very new to coding, so try to explain things in simple terms)
I decided to do a hover drop-down menu which makes things a lot easier, but thank you for your answers!
There are different ways to do this. One is to use jQuery (a Javascript extension), like Branden Keck showed it to you. Another way is to use only html and Javascript: There is a html attribute which creates an Javascript event:
<div id="myDiv" onclick="clickEvent()">Some text</div>
clickEvent has to have brackets in it because it's a Javascript Function. Your Javascript could look like something like this then:
function clickEvent() {
document.getElementById("myDiv").innerHTML = "Hello World";
}
Here a snippet for that:
function myFunction() {
document.getElementById("myDiv").innerHTML = "Hello World without jQuery!";
}
$("#myDiv2").click(function() {
$("#myDiv2").html("Hello World with jQuery!");
});
$("#myDiv3").click(function() {
$("#hiddenDiv").slideToggle(750); // 750 is the sliding time in ms
});
#myDiv,
#myDiv2, #myDiv3, #hiddenDiv {
background: #0000ff;
color: #ffffff;
transition: 0.5s all;
-webkit-transition: 0.5 all;
font-family: "Arial";
width: auto;
height: auto;
font-size: 1.3em;
margin: 0.4em;
padding: 0.2em;
border-left: 1px groove #f0f0f0;
border-top: 1px groove #f0f0f0;
}
#myDiv:hover,
#myDiv2:hover, #myDiv3:hover {
background: #ffffff;
color: #000000;
padding: 0.22em;
box-shadow: 0.22em 0.22em 0.44em #000000;
}
#myDiv2, #myDiv3 {
background: #ff0000;
}
#hiddenDiv {
background: #00aa00;
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<div id="myDiv" onclick="myFunction()">Click this div! Without jQuery</div>
<div id="myDiv2">Click this div! With jQuery</div>
<div id="myDiv3">Toggle hidden Text With jQuery<span style="font-size: 0.7em;font-family:Arial;font-style:italic;"> May lag because of snippet.</span></div>
<div id="hiddenDiv">You found me!</div>
You say you are very new to coding. Have you read about jquery at all? I would definitely suggest it. It is very possible to make things happen when a <div> tag is clicked with jquery functions. Here is an example:
$("#IdOfDivTag").click(function(){
alert("The paragraph was clicked.");
});
You will have to add an id or class attribute to the div tag you want an action to happen with (unless you want the same action for all <div>, in which case you can use "div" in the jquery statement).
To implement jquery you need at add a jquery library to your code... You can start here: http://www.w3schools.com/jquery/jquery_get_started.asp

How to Wrap Text Within an Image-Link? HTML CSS

I have some code which displays images from imgur.
When hovering over an image, I want the title attribute to appear at the top of the image.
I have achieved all of this, but when the text becomes visible, it only appears on one line and writes over itself when it runs out of space, as in the image.
I would like the text to start on a new line once it reaches the end of it's container.
I have tried adding word-wrap: break-word; to each of the CSS selector below, as well as to a P selector (as the link is wrapped in a p-tag).
Any advice on how to resolve this is much appreciated!
I have the following html:
<section id='photos'>
<p>
<a class='hovertext' href='http://i.imgur.com/gallery/eWlGSdR.jpg' title='Opened my window shade while flying over Japan, noticed a volcano was erupting. (OC) [2448x2448]'>
<img src='http://i.imgur.com/eWlGSdR.jpg' alt=''>
</a>
</p>
And the following CSS:
a.hovertext {
position: relative;
text-decoration: none !important;
text-align: left;
}
a.hovertext:before {
content: attr(title);
position: absolute;
top: -1;
padding: 0.5em 20px;
width: 90%;
text-decoration: none !important;
color: red;
opacity: 0.0;
}
a.hovertext:hover:before, a.hovertext:focus:before {
opacity: 1.0;
}
As Dinesh said in the comments, this was caused by poor code awareness, as elsewhere in the code, I was calling 'line-height:0;' on the #photos element.
Removing this solved the problem.
i think you coul use some java script on this, if you only want to make it add a extra line to it, correct me if im wrong.
Here's an example what i think you mean:
First add this text next your class="hovertext" :
id="HoverText"
Add this part after your body or paste the code between script into a .js file and call it with
<script src="filename.js"></script>
<script>
HoverText=document.getElementById("HoverText");
HoverText.onclick=function(){ClickToShowText()};
function ClickToShowText(){
HoverText.innerHTML+="<br>New line with text";
}
</script>
just use the break tag at the end of the text that's supposed to be on the first line.
</br>
easy

How to open a new page from a button in a Dialog Box?

How do I open a new page from a button in a Dialog Box?
This box is created using:
var html = HtmlService.createTemplateFromFile('File')
And this is the File.html:
function sabermais(){
window.open('www.google.com')
}
<input type="button" class="action" value="Learn more" onclick="sabermais()" />
It works if the box is called with:
var html = HtmlService.createHtmlOutputFromFile('File')
But in this case, I can't use scriplets,and I need them.
This sounds a bit confusing but I guess someone can help.
Thanks in advance!
You need to use IFRAME mode:
var html = HtmlService.createTemplateFromFile('File')
.evaluate()
.setWidth(450)
.setHeight(450)
.setSandboxMode(HtmlService.SandboxMode.IFRAME);
My first answer below:
And <a> tag in a dialog box will open a link in a new tab.
button
That's not a button, but you can use a link, and style it to look like a button.
<a style="border: 1px solid #990000;
background-color: #CCCCFF;
margin-left: 10px;
padding: 0 1em;
height: 2em;
width: 30px;
cursor: pointer;
text-align: center;
" href="https://www.google.com">button</a>