Iron Router , change URL without changing browser history - meteor

Using iron router version 0.9.4
How to update URL query parameters without changing the browser history?
I have a bunch of select boxes which can update the URL query parameters. In some cases I'd like to update the URL without adding an additional entry into window.history. A lot of templates are dependent on the Router.current().params reactive variable, so I need to update that as well when changing the route.

Iron Router has an optional parameter in the Router.go function which you can pass in {replaceState:true} . This will update the URL without storing the URL change in the window's history.
This is working in Iron Router 0.9.4
var path = Router.path('myRoute',{_id: myId}, {query: myParams});
Router.go(path, {replaceState: true});
If you are on a newer version of Iron Router, the order of arguments has probably changed a little, according to this github issue this would be the new order :
Router.go(path, {}, {replaceState:true});

You can use vanilla JavaScript:
window.history.replaceState(yourNewUrl);
Here is some some documentation. As it's a modern feature, if you want to support older browsers, you can use a polyfill.

Related

Is it possible to add custom request headers when using chrome custom tabs?

Planning to use chrome custom tabs, however before I start I wanted to know if its possible to intercept the request and set any headers in the request similar to WebViews ?
Read through the documentation and could not find any examples or references. All I could find is the onNavigationEvent callback that tells what url browser is trying to load.
Also is it possible to stop navigation for any url if required ?
As of recent updates of the library, you can now add Bundle and pass it to the CustomTabsIntent intent as extra with key Browser.EXTRA_HEADERS
Bundle headers = new Bundle();
headers.putString("header1", "value1");
headers.putString("header2", "value2");
customTabsIntent.intent.putExtra(Browser.EXTRA_HEADERS, headers);
As of today, it is not possible to set custom request headers. It's not possible to stop the navigation.

Is it possible to change the URL without re-loading the page in Meteor?

I remember in Angular, I was able to dynamically change the URL without re-loading the page simply by changing $location
Is this possible to do something similar in Meteor?
I've tried using Router.go but that does reload the page, clearing all the fields.
You can use pure JavaScript (in modern browsers) to change the URL without reloading the page. See https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history As an example, evaluate history.pushState({}, "A new page", "myNewPage.html") in the console in your browser, and notice the change in the adressbar.
I guess Iron Router uses this under the hood when you change page.

How to let menu item execute Javascript in Joomla 3.2?

Before 3.2, I can set the menu item type to "external link" and then set the link as
"javascript:myFunction()"
When clicked, the menu item will call the JavaScript function. But after I upgraded to 3.2, when I did the same thing and tried to save the menu item, it said "Save not permitted".
Did 3.2 block this usage? If yes, how do I get my JS function executed by a menu item?
I've came up this problem a while ago, in Joomla version 3.2.1 concerning a 'Skype' link, e.g.
skype:myloginname
This has to do with the protocol types that are allowed and are defined in this file:
/administrator/components/com_menus/controllers/item.php, line ~180.
There is an array that defines the acceptable schemes:
$scheme = array('http', 'https', 'ftp', 'ftps', 'gopher', 'mailto', 'news', 'prospero', 'telnet', 'rlogin', 'tn3270', 'wais', 'url', 'mid', 'cid', 'nntp', 'tel', 'urn', 'ldap', 'file', 'fax', 'modem', 'git');
When adding skype at the end of the list Joomla! allowed saving the external link. The same applies for javascript. In any case you should consider any security risk that comeswith this solution.
In addition, you should take into mind that this override may be discarded in any future update of joomla.
Technically speaking Joomla thinks that javascript is a protocol, like HTTP & Co., it looks it up inside a list of known protocols, it does not find it and it throws an error.
Start reading at around line inside [MenusControllerItem::save()][1]. So basically it has nothing to do with the fact you are trying to use some JavaScript, this is just a side-effect.
While using JavaScript in the External Link is not really an advertised feature but rather said a loophole, it does break b/c if you have used before.
You can:
Open an issue in the Joomla Issue Tracker and report this issue, get some community feedback. The fix is really easy, it just needs to get accepted.
Use the suggestion below:
Instead of link put #
Set the field "Link CSS Style" to something that does not colide with other classes, eg. my-function
Save
You can use jQuery to intercept the click event on the link and to make it run your function. See code below:
jQuery(document).ready(function($){
// Select element based on the class set in Joomla backend
$( ".my-function" ).on( "click", function(e) {
// Do not follow the link
e.preventDefault();
// Call function
myFunction(1);
});
});
function myFunction(x)
{
alert("I was called" + x);
}
Update: after a short discussion with the commiter of the change, I understood that it may be related to a security issue. So it may be on purpose after all not to allow js.

Upgrading to new asynchrous Google Analytics code - should you do it?

I had read somewhere and have now forgotten that upgrading to the new asynchronous code will not enable one to track actual clicks for downloading items when user stays on the same page and that for tracking that you need to use the old version of GA code.
My question is, is that still the case and does anyone have any other reasons for not upgrading to use the newer asynchronous tracking?
thanks
Hmm...are you sure the "old" version of GA automatically tracked downloads? AFAIK GA never automatically tracked download links, that you always had to attach GA code (like a _trackEvent call) to your links yourself. But in any case, it's pretty easy to do it yourself, so it's really not a big deal. Plus, you get lots of benefits upgrading, and one day it may not even be an option to stick with the old version...
If you have jQuery you can for example do this:
// file types you want to consider a download
var downloadFileTypes = ['pdf','doc','docx','mp4'];
$(document).ready(function() {
$('a').filter(function() {
var ext = $(this).attr('href').split('.').pop().toLowerCase();
return ( $.inArray(ext, downloadFileTypes )>-1 );
})
.click(function() {
_gaq.push(['_trackEvent', 'Downloads', $(this).attr('href')]);
});
});
If you do not have a framework like jQuery, you can still do this easy enough with .getElementsByTagName() and using regular loops and conditions instead of the jQuery conveniences like .filter and .inArray
edit: Some things to note about that example:
the jQuery code was an example to hook the GA code to standard links pointing to the file types you specify in downloadFiletypes. It will only apply to links that exist at the time the code is executed. If you have links that may be dynamically generated on the page later, consider looking into .on() instead of .click()
you will need to make tweaks to matching links you want to consider downloads if they do not point to regular files with extensions. For instance, some websites have a controller script that expects a parameter with an ID and it dynamically serves up a pdf or whatever..if your files are like this, you will have to alter the logic to look for that instead.

conflict between jquery-1.2.6.min.js and jquery-1.4.2

Hi all
i put jquery file in master page version jquery-1.4.2.min.js and in another page
jquery file jquery-1.2.6.min.js just in Firefox the jquery features don't work
JavaScript doesn't support class, function or whatever library.
You're just including jQuery twice - different versions -.
If you want to use both, you'd need to change jQuery prefix.
Version A: $
Version B : $$
Or any other valid prefix.
You can do so by changing jQuery object name to jQueryA and jQueryB, and at the end of jQuery source code, change the "$":
// Expose jQuery to the global object
window.jQueryA = window.$ = jQueryA;
...and:
// Expose jQuery to the global object
window.jQueryB = window.$$ = jQueryB;
It's not a good approach so far, but maybe your requirements are leaving an old version of jQuery for some tasks because you don't support some code, and you want to do some new feature with another and newer jQuery version...
What happens when you include jquery a second time, is that it forgets all customizations that has been made since the first include. So the solution is simple: Dont include it twice.

Resources