Add custom javascript to wix - javascript

I am trying to add custom javascript to wix, but it doesnt work. I have tried almost all I found on google but it doesnt work.
<script type="text/javascript">
window.parent.location.href = "https://url/track"
</script>
The script above needs to be loaded on every wix page, it contains redirection
I was wondering if this is possible in wix?

The way to add custom code to each page in a Wix site is by adding Site code in the built-in IDE.
To access it, enable Dev mode at the top menu and click the Site tab at the editor.
Note that you can't access the DOM directly. However, Wix has a pretty rich API that may cover your needs.

looks like you need to use the wix location API: https://www.wix.com/corvid/reference/wix-location.html#to
From my limited knowledge of wix it seems like your implementation is just wrong for the problem you're trying to solve.
I had a quick read of this article which isn't too old: https://www.wix.com/corvid/forum/community-discussion/page-redirect and it seems like a better approach.

Make sure you've enabled DEV mode and then open the script panel at the bottom of the page.
First, you should import the module that contains the method you need. In your case, that would be wixLocation. Inside the onReady function, you should call winLocation.to method.
import wixLocation from 'wix-location';
$w.onReady(function () {
wixLocation.to("http://some.new.location"))
});

Related

SEO problems using jQuery load()

I have created a modal window with load function with links inside the modal window. The crawler is unable to read and index those links. I need a way to make crawler index those links.
I see websites using angular js ranking such as https://www.dailyobjects.com/designer-cases (This website has a similar modal window) ranking on top in Google Search and I google never reads or index angular js made pages.
They managed to crawl it, so there must be a way to crawl a javascript modal window which I have made.
How can I achieve this?
Angular uses Server-Side Rendering(SSR) to fix SEO issues. Just read more on this.

Tag Editor- $(...).jsonTagEditor is not a function

I just tried to implement the json tag editor to create a tag editor.
I want to implement it in a bigger laravel project. Therefore I included jQuery, as well as the js and css file from the json tag editor. It's all loading fine, which I figured out under the network tab.
Now I have:
an input element:
<input id="keywords" class="form-control" name="keywords"
autofocus></div>
and on top of the page I have:
$().ready(function(){
$('#keywords').jsonTagEditor();
});
But i get an error saying
Uncaught TypeError: $(...).jsonTagEditor is not a function...
As I said, the files are loaded as I can see in the network tab...
Any ideas what the problem could be?
Again to make everything clear, I'm using laravel, so the files are all included in the master-layout file and I'm trying to use it in a document that extends this master template. But shouldn't change anything as I'm already using some other plugins that work fine that way.
Any ideas?
After some discussion in chat, the problem turns out to be the suspected re-import and re-initialization of jQuery. The Laravel framework has it's own import of jQuery that happens via require(), and that was the happening after the plugin in question was imported.
Moving the plugin import to the end of the <body> worked around that, but in addition the plugin (as of this writing) has a bug and must be initialized with an empty object passed in (or probably any other value):
$("#keywords").jsonTagEditor({});
You are missing document and just to be certain that the element is accessible, place your script before the ending '</body>' tag so that it loads your page content first.
$(document).ready(function(){
$('#keywords').jsonTagEditor();
});
You forgot to write document
Instead of this
$().ready(function(){});
Use this
$(document).ready( () => {});
The => means, that you use newest standarts of JS
Or you can just use this alternative jQuery tagEditor

Problems in implementing Disqus plugin due to jQuery issues

I am working on a blog website at http://d361.azurewebsites.net/Blog. I have used a template for full page flip from http://tympanus.net/codrops/2012/12/11/fullscreen-pageflip-layou which uses javascript and jquery, other than the obvious.
I have 2 problems.
I need disqus plugin on every article of the blog. But since the whole website is basically one single webpage, I have not been able to implement it. Further anchor tags are not working.
Currently the disqus plugin is working in case of the first article only.
I am also using social sharing buttons on the site. Again, they share only the mail website link, i.e d361.azurewebsites.net/Blog and not the actual articles. I tried to use anchor tags but it is not working.
Kindly help me out here. As you must have already known, I dnt know much beyond html and css.
Disqus won't work with single-page applications out of the box, you have to use our AJAX protocol to reload the thread with the new information. The process is documented here: http://help.disqus.com/customer/portal/articles/472107-using-disqus-on-ajax-sites
Whenever the page content is changing, you would call DISQUS.reset like this:
DISQUS.reset({
reload: true,
config: function () {
this.page.identifier = "new_disqus_identifier";
this.page.url = "http://example.com/#!new-url";
}
});

I can't get the toggle control with document.GetElementByID() in the windows8 setting charm

I'm very new to javascript, so this is confusing me. All of the settings charm tutorials only show how to put the controls into the settings charm, but none of them say how to find the information gotten in them.
I tried to do one of these (like I do in the main program):
var muteToggle = document.GetElementById("Mute");
where "Mute" is the id in the separate html file.
muteToggle just ends up being null all of the time. I tried putting it after
WinJS.UI.ProcessAll().then(function completed() {...
but that didn't work either. Everything else is the same as in this page: http://msdn.microsoft.com/en-us/library/windows/apps/hh780611.aspx
Make sure you're doing it in the ready function of the js file that is referenced from your settings HTML. Try opening the JavaScript console or QuickWatch while broken at that line and also look at the DOM Explorer to see if you can find your toggle control. You should be able to access it though. Also, try element.getElementById instead of document.getElementById. Either should work actually, but as long as you're troubleshooting. Good luck.
Your problem is that you are trying to get a reference to the HTML element from the code running during the app activation. Although that piece of code may define the HTML to be loaded for a settings pane, it does Not actually load the HTML into the DOM. You just simply can't get the instance from that location.
What you need to do is have the settings flyout have its own js file that implements IPageControlMembers. In particular, you need to implement the ready method. This method is called once all the HTML and controls are loaded for the page, including your toggle. The link has an example of how to do this.
Also see:
WinJS.UI.Pages.define
Using single page navigation

Dynamic content with JavaScript which allows linking

Let's say I want to create a website that contains one page. All the content is dynamic and generated using JavaScript with DOM replacement. The good thing about this is that it creates a better user experience, especially for applications that contain catalogues (online stores, galleries, etc). The problem now comes with linking. Let's say I'm browsing the site and I feel like sharing that particular thing I'm looking at with someone, but the problem is the link is always the same since it's JavaScript that's doing the magic. So the question comes: how can I create a fully JavaScript run website while maintaining the ability to link?
Now there's hash linking, but I'm failing miserably. I've tried overriding all <a> tags, changing the hash, and preventing the default action like so
$("a").click( function(){
window.location.hash = $(this).attr("id");
processHash();
return false;
});
Yet, it will randomly scroll my body for no reason.
I'd like some insights on the restrictions of linking in a fully dynamic website. Thanks.
Here is one simple thing you can do:
window.onload = function () {
processHash();
}
or it can be using jquery $(function () {...});
what happens here is when the page is loaded example http://www.example.com/#some-link
the page content is loaded first then your function that handle links processHash(); will do its work
not even the new and shiny jQuery mobile library is 100% ajax, but it's close. Obviously with a very modern browser, checkout this doc site done in jQuery mobile: http://jquerymobile.com/test/
If you dig in the docs a little you see how they use hash linking with the framework and html5 data-content="page"
each <div data-content="page">Is an independent page, if I remember right</div>

Categories