How to make simple modal login work with non-modal wordpress login screens - wordpress

The SimpleModal Login plugin for wordpress seems to have pretty nice functionality for creating login, registration, and forgot_password modals that can be made to pop up in the foreground using the link: Login but a problem occurs when accessing a non-modal WP login screen ("www.site.com/wp-login.php" or "/wp-admin") where the links from that WP login screen start to be read by the modal .js file before the simplemodal html has fully been established (which it hasn't on a non-modal wp-login page).
So, how can you make those links work for those non-modal access points? See my own solution below...

Towards the top of the .js file of the theme you are using (ex: .../plugins/simplemodal-login/js/default.js), right inside the init:function{ bracket, place the following:
var this_url = window.location.href;
var is_nonmodal_login = this_url.search(/wp-login|wp-admin/);
if (is_nonmodal_login >= 0){
return;
}
This is a somewhat simple solution that simply stops the script from continuing any further and allows for the actual default href values of the non-modal screens to be loaded into the browser, and the user redirected appropriately, without the script operating on the url and continuing to try to .show a modal dialog.
Note however that there may be other ways to access the wp-login for your site that should be addressed too...

Related

Server side analytics of outbound links

The problem: We count clicks on external links with Google Analytics (GA). But because external links are opened in a new tab, we are not 100% sure that browser's tab was really opened and that a third-party site was really loaded even in opened tab.
The solution: Do not open direct links to 3-d party web-sites directly in the new tab, but only through some interceptor that will collect statistic on a server side before redirection to the target url. Thus, we will be able to to catch the moment of loading a third page in a new browser window.
Therefore, we need a service that will take full URL as a parameter, collect statistics, and then redirects to the passed URL, like this:
https://magicclickcounter.com/abc?url_to_redirect=http://urltoexternal.link/123 which will collect statistics and redirects to http://urltoexternal.link/123
Any ideas how to achieve this with GoogleAnalytics?
UPD: Firebase DynamicLinks is not appropriate for us because we have to use shortened urls(deep API integration) or there will be no statistic for full urls created manually or via SDK-builder.
UPD: The main problem in our case is that we use a HTML canvas in our page and "clicking area" is inside canvas. Therefore we use next code to open a new window:
this.pixiLayout.App.renderer.view.addEventListener('click', () => {
if (this.pixiLayout.externalUrl) {
window.open(this.pixiLayout.externalUrl, '_blank');
}
});

Open a link in a frame/lightbox

im using wordpress and want to add a link which open in a frame/lightbox. Cant find a small solution for that.
There should be no new window. Just a content box which appear inside the page where i am. I hope u know what i mean
That should be pretty easy using the Easy Fancybox plugin.
Citing the entry from the FAQ section of the plugin's page:
Can I display web pages or HTML files in a FancyBox overlay?
Yes. First, enable the iFrame option on Settings > Media. Then, in your post or page content create a link to any web page or .htm(l) file in your content. Then switch to the Text tab in the Classic Editor or to Edit as HTML (under More options in the block menu) in Gutenberg, find the link <a ... > tag and give it a class="fancybox-iframe" attribute.
Voilà !
Beware, though, that:
Note: Not all external web pages are allowed to be embedded in an iframe and may be blocked by a server response header or script. The result will be either an empty/blank light box or the target page “breaking out” of the light box and loading in the main browser tab.
And you'd probably face the same problem with any other iframe solution. So that would work better with locally served pages.

Prevent jQuery mobile link caching

I have a asp.net website with some header links in master page. For some of them I added link to jQuery mobile script to format those specific pages (forms) to look good on phones/tablets.
But after I load one of those pages and then click on some other page, it somehow caches the current page and although I can see the correct page being loaded for split second, it then reloads previous page. I don't know why this happens, but I know that culprit is the jQm link, because if I remove it, it works like expected (without the mobile design though).
I don't use data-role="page" attribute or anything, just classic asp.net page.
jQuery Mobile uses it's own kind of navigation model by default. It injects multiple specifically formatted pages into current page using AJAX. You probably need to disable it using code snippet below:
$( document ).on( "mobileinit", function() {
$.mobile.ajaxEnabled = false;
});
For more information check jQuery Mobile documentation navigation model and global configuration pages.

Prevent Google Chrome Content Scripts from interfering with webpage DOM CSS definitions

I am building a Chrome extensions which injects a decent amount of JavaScript, CSS, and HTML into the page DOM for the current webpage tab. It it does so to show a Modal window with my extensions functionality in that modal.
I cannot use the background or popup scripts to do what I need to do so I have to use a content script which injects into the actual page DOM.
My issue so far is I have to be super careful with CSS class names and JS as well as I have discovered if the page has a CSS class matching the name of any of my extensions CSS, my extensions ends up over-riding the pages CSS!
I have seen that some other extensions that have to do a lot of HTML, CSS, JS into the content end up injecting into there own Iframe in the page which helps prevent this name collision.
Is using an Iframe the standard best practice in this case?
One of the features in my extensions is to do full-page screeenshots which require my contnet.js script to send a message to my background.js script which is responsibble for calling the CHrome API and taking the screenshot of the current scroll position in the pages viewport.
user clicks button in DOM modal windows
content.js sends message to background.js with the coordinates of the viewport.
background.js takes the screenshot with those coordinates. THen sends a message back to content.js.
content.js then scrolls down the page to the next area of the viewport for the next screenshot and then sends those new coordinates back to background.js.
this cycle continues until a shot of the whole page is made and stiched together and then sends back the URL of the new image to content.js when done.
Because both the Chrome API needs to sends messages back and forth between my content.js and background.js and then also if there is an iframe the iframe has to send messages back and forth with the page and the iframe.
Because of this I am not sure if I could use an iframe or not even?
Also if I did use an iframe, it would not load the content from a remote server but instead would be loaded into the page as html.
So is there a best practice for doing this?
Use inline styles instead
You can wrap your css in content.js then apply it to your target elements, it won't interfer the original design of the webpage
Use Shadow DOM
It provides encapsulation for js/css and makes it easy to ensure your components separate from the DOM of the main document.

How to apply css to google calender iframe...?

I want to apply css to google calender iframe. I had tried with Jquery but it gives JavaScript security error. However I also tried this link
Got success but many of its links goes to 404 page as it takes my domain as base URL
You will face a security error when you apply css using javascript to an iframe that contains a page in a different domain. but this problem has a workaround by using document.domain if both documents are on the same top level domain, are using the same protocol & you can add the following line of JavaScript to the page in the iframe:
document.domain = "example.com";
the page containing the iframe needs the same line to make the domains match. Once this is in place, the script running on your main page is allowed to access properties of the document in the iframe element –
You cannot apply css to a iFrame ...
An iframe is a 'hole' in your page that displays another web page
inside of it. The contents of the iframe is not in any shape or form
part of your parent page.
From here
The reason behind that is security. If you have blabla.com in one
window and gmail.com in another one, then you’d not want a script from
blabla.com to access or modify your mail or run actions in context of
gmail on your behalf.
From here
If the iFrame is on the same domain and it doesnt violate the "Same-origin policy", you can work around this situation like this:
$('iframe').load( function() {
$('iframe').contents().find("head")
.append($("<style type='text/css'> .my-class{display:none;} </style>"));
});
Solution posted here
Anyway, if you are not violating the "Same-orgin policy", you probably don't want to use an iFrame.

Resources