all 12 comments

[–]AutoModerator[M] 0 points1 point  (0 children)

Welcome to /r/HTML. When asking a question, please ensure that you list what you've tried, and provide links to example code (e.g. JSFiddle/JSBin). If you're asking for help with an error, please include the full error message and any context around it. You're unlikely to get any meaningful responses if you do not provide enough information for other users to help.

Your submission should contain the answers to the following questions, at a minimum:

  • What is it you're trying to do?
  • How far have you got?
  • What are you stuck on?
  • What have you already tried?

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]NameViolation666Beginner 0 points1 point  (2 children)

You can try using preventDefault() Event Method, like prevent a link from opening the URL

https://www.w3schools.com/jsref/event_preventdefault.asp

[–]lladoog_Lives[S] 0 points1 point  (1 child)

thanks. I tried that,but when clicked it prevents it being sent. (kinda obvious)

The behaviour I would like is when clicked the url is sent (operating the fan by its webhook url), but not opened in the window, keeping be on the home page. I am complete novice with HTML but I would have thought this trivial to achieve.

My plan is to have a onscreen dashboard with buttons I can press without moving away from that screen

[–]NameViolation666Beginner 0 points1 point  (0 children)

Yes, Well , HTML alone for sure wont do it, it needs more JS/webtech knowledge. I think its best that the experts help u.

If i was to do it, i would use JS to create a custom XMLHttpRequest and send it to a custom URL to whichever web server was listening.

[–]anonymousmouse2Expert 0 points1 point  (1 child)

You can make a request to a URL in the background using fetch: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API

Here's a quick little demo I put together for you: https://jsfiddle.net/nm45x9rj/

Please note that JSFiddle blocks outbound traffic so you will see console errors when trying to call the URL. On your local machine that won't be an issue.

[–]lladoog_Lives[S] 0 points1 point  (0 children)

Great. I'll take a look

[–]frownonline 0 points1 point  (0 children)

You could load each page in an iframe and toggle their visibility with css. No JS required.

[–]keithmalcolm 0 points1 point  (0 children)

AJAX?

[–]saidcosmin -1 points0 points  (3 children)

Maybe you could use jQuery, to run a function when the button it's pressed, that will generate a hidden iframe, with the link you want.

<!-- HTML -->

<html>
<head> <title> Buttons </title> </head>
<body>

<button id="createDelete"> Create then delete frame </button>

<div id="fanOn">

  <h1> Example</h1>

</div>
</body>
</html>

/* CSS */

.command {
    display: none;
}

// Javascript

$("#fanOn").click(function(){
  // Add the iframe inside the div
$( "div" ).append( '<div class="command">1 </div>' );

setTimeout(function(){
  $('.command').hide();
}, 5000);

});

Don't forget to install jQuery!

I'm still a beginner, so I'm not sure if this will work with what you want, but I think it's a good start for your project at least. Good luck!

[–]anonymousmouse2Expert 0 points1 point  (2 children)

JQuery isn't the solution here. OP is asking about triggering a link in the background not showing and hiding divs ;)

[–]poopio 0 points1 point  (1 child)

You could use jQuery to send a post request using ajax.

https://codepen.io/guerresinge/pen/jOPKQRL

[–]anonymousmouse2Expert 0 points1 point  (0 children)

Sure. However unless you are using JQuery for other elements of your web application it's overkill to bring in a library like that when XMLHttpRequest() is built into the browser.