this webpage is built for firefox, but it has to display a link which is to be opened in IE. So I am trying to use a code I found on net. but it is not working. what am I missing?
javascript code:
<script type="text/javascript">
$(document).ready(function(){
function myFunction()
{
alert("opening now....");
var localFile = Components.classes["#mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
var process = Components.classes["#mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess);
var url = content.document.location.href;
var args = ["-new-tab", url];
localFile.initWithPath("C:\\Program Files \(x86\)\\Internet Explorer\\iexplore.exe");
process.init(localFile);
process.run(false, args, args.length);
}
});
HTML Code:
<p>Click the link top open in IE</p>
open in IE
When I click on link, it opens the google page: in same window, in same borser, in same tab.Pl advice.
thank you.
myFunction is not defined in the global scope. Adding it to the dcoument ready callback guarantuees this.
You could move myFunction outside of the document ready callback. However:
In this case I would attach a click handler using jquery as follows
$(function() {
$("a").click(function() {
// do stuff
});
})
Note this selects all anchors and applies the same event handler. Ideally you would use a selector.
$("#myGoogleLink").click(function() {
})
Add the id myGoogleLink to your html anchor
Related
I am trying to load a web web page inside a div with an ajax call but not working. it's showing this error
jquery.min.js:2 [Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience
how to solve this issue.
<div class="warper">
<div class="menu">
Home
Page One
Page Two
Page Three
</div>
<div id="content"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function () {
$("#content").load('home.html');
// Set trigger and container variables
var trigger = $('.menu a'),
container = $('#content');
// Fire on click
trigger.on('click', function () {
// Set $this for re-use. Set target from data attribute
var $this = $(this),
target = $this.data('target');
// Load target page into container
container.load(target + '.html');
// Stop normal link behavior
return false;
});
});
</script>
Just to be specific, you're trying to load content into a div, not a webpage. A webpage would have it's own document and DOM and such and would require an <iframe>
Your issue could be with your use of .data() instead of .attr(). Although in my answer I use the vanilla javascript .getAttribute(), which does the same thing and saves a jquery call. Essentially you're code is trying to :
container.load(undefined + '.html');
I've never used the load method like this, (I don't know why they decided to overload it for event handeling and ajax) but it would look something like this:
<script>
$('#content').load('home.html');
$('.menu').on('click', 'a', function (e) {
e.preventDefault(); //stop normal link behavior
$('#content').load(this.getAttribute('data-target') + '.html');
});
</script>
Also, if your script is at the bottom of the <body>, you don't need $(document).ready(), as the code won't run until the document is ready anyway.
I have this burger menu which I can't invoke the button onclick event function when I click it.
HTML code:
<button class="nav-aside-close"><i class="fa fa-times"></i></button>
JQuery code:
$('.nav-aside-close').on('click', function () {
console.log('test');
$('#nav-aside').removeClass('active');
$('#nav').removeClass('shadow-active');
});
If I click any area outside the burger menu, it works. Below is the code which works:
$(document).click(function(event) {
if (!$(event.target).closest($('#nav-aside')).length) {
if ($('#nav-aside').hasClass('active')) {
$('#nav-aside').removeClass('active');
$('#nav').removeClass('shadow-active');
} else {
if ($(event.target).closest('.aside-btn').length) {
$('#nav-aside').addClass('active');
$('#nav').addClass('shadow-active');
}
}
}
});
Actual code I have uploaded it at http://js.findingsteve.net
If you're using Chrome, open up DevTools (F12) and do this on the Console tab and hit Enter:
getEventListeners(document.querySelector('button.nav-aside-close'))
If you see any click events registered, it should work.
Anyway, I noticed you are putting the main.js file on the <head> and not using jQuery.ready, so your click handler is essentially never attached since the DOM element is not ready by the time the script executes.
Solution:
Add the jQuery alias $ on the very first line of your JS file, that is a shorthand for jQuery.ready BTW.
$(function($) {
"use strict"
// Fixed Nav
var lastScrollTop = 0;
Don't forget to also remove the jQuery function assignment from the end of the line, since it's no longer an IIFE.
setStickyPos();
})(jQuery);
Alternative, you can keep everything as is and move your main.js file to the <body> element, right before the closing </body> tag. That is pretty much the same as having the scripts executed when all the elements above it have finished loading.
It's probably because .nav-aside-close is hidden in the initial render.
Try this instead:
$("#nav").on("click", ".nav-aside-close", function() {
$("#nav-aside").removeClass("active");
$("#nav").removeClass("shadow-active");
});
Based in #Ana Liza Pandac comment
It should be:
$("#nav").on("click", "#nav-aside .nav-aside-close", function() {
$("#nav-aside").removeClass("active");
$("#nav").removeClass("shadow-active");
});
Your tree is: nav->nav-aside and obj with class nav-aside-close
The difference is on:
$("#nav").on("click", "#nav-aside .nav-aside-close", function()
I want to know that how can i create a JavaScript code that must open a new page at click anywhere at website. currently i am using onload script.
<script type="text/javascript">
function open_on_entrance(url,name)
{
window.open('http://realestatepakistan.pk','Real Estate Pakistan')
}
</script>
<body onload="open_on_entrance()"></body
but onload is not effective as it opens very low number of pages. A must must open page script needed fro my web http://pkr.com.pk/.
This code will open the popup when you click anywhere on website.
<script type="text/javascript">
var shouldOpenWindow = true;
function open_on_click(url,name) {
if (shouldOpenWindow) {
window.open('http://realestatepakistan.pk','Real Estate Pakistan');
// if you want that only on first click the popup must be opened, and not on any subsequent clicks, then do this
shouldOpenWindow = !shouldOpenWindow;
}
}
</script>
<body onclick="open_on_click()"></body>
Place this code in a script tag right before your closing </body> tag that way it will load after the dom has loaded. You will notice that I removed your parameters from your function because you were not using them inside of your script. Make sure you change the values of window.open to the values you need for your script.
JavaScript:(live example)
function open_on_entrance() {
window.open('http://bytewarestudios.com','Welcome to Byteware Studios');
}
document.addEventListener("click", function() {
open_on_entrance();
});
If you decide to the add the parameters back in make sure you supply them to your function when you call it.
Example Using Parameters:
function open_on_entrance(url,name) {
window.open(url,name);
}
document.addEventListener("click", function() {
var url = 'http://bytewarestudios.com';
var name = 'Welcome to Byteware Studios';
open_on_entrance(url,name);
});
I create a web app that looks like this:
When i click the run model, i want that the form :"Dashbord", will open.
The JS code:
<script>
window.onload = function () {
function newDoc() {
window.location.href("#http://127.0.0.1:8100/#dashboard");
}
}
</script>
When The "Run Model" button onClick activate the function: newDoc().
The problem is: that in my URL path it is written: http://127.0.0.1:8100/#dashboard
but the 'Dashboard' form is not logged. it stays in the same page.
What should i do?
window.location.href is not a method, it's a property.
Try assigning it instead (also note, I removed the leading # character)...
window.location.href = "http://127.0.0.1:8100/#dashboard";
You also need to move your function outside of the window.onload event...
window.onload = function () {
}
function newDoc() {
window.location.href = "http://127.0.0.1:8100/#dashboard";
}
The onload event handler is generally only needed when you're dealing with specific elements on the page that won't be available until the page has finished loading.
By putting the newDoc within the onload event, you were effectively hiding it from being used directly by other events.
Need to write selector to links in leaflet popup.
I'm try something like this, but it's not work:
L.marker([39.74, -104.99]).bindPopup("<a href='#' class='trigger-to-page'>test</a>").addTo(cities);
$( document ).ready(function() {
$('a[class=trigger-to-page]').click(function() {
console.log("123");
});
});
http://jsfiddle.net/x52j9da7/4/
Can anyone help?
You can only query elements in your popup's HTML content once the popup has opened. The content gets added to the DOM when the popup opens en removed again once it closes. How you want to solve this depends on what you're actually trying to do but there are multiple ways:
Use L.Map's popupopen event and directly get a reference to the popup's content once it opens:
map.on('popupopen', function (e) {
var link = e.popup._contentNode.firstChild;
});
Or don't create the link from a string content but create the actual element and store a reference to that, so you can use it when you need it:
var link = L.DomUtil.create('a');
link.href = '#';
link.textContent = 'Test';
L.marker([39.74, -104.99]).bindPopup(link).addTo(cities);