Router push is not working properly in Vue 3 - vuejs3

As shown in the code below, there is a code that goes to home when clicked. There is no problem in moving the router-view header when running the server, but if you enter the path directly in the url and click the dashboard function again, the js code animation of the page does not work, but if you press f5 it works. No errors unless you go directly to the URL. I don't know why this error is appearing.
This function only works when you refresh with f5
<script setup>
var scrollEvent = function() {
var scroll = window.innerHeight + window.scrollY
var itemList = document.querySelectorAll('.mainsection .section')
Array.prototype.forEach.call(itemList, function(section){
if(section.offsetTop < scroll) {
section.classList.remove('animatable')
section.classList.add('animated')
}
})
}
<script>
dashboard router code
const dashboard = () => {
router.push({
path:'/home',
})
}

Related

How to open A-Frame inspector programmatically when the page loads

I need to open the inspector automatically when the page loads.
You can invoke the openInspector function manually after a-scene loads:
var sceneEl = document.querySelector('a-scene');
sceneEl.addEventListener('loaded', function () {
sceneEl.components.inspector.openInspector();
});
Working example:
https://glitch.com/edit/#!/brawny-candle-shrine?path=index.html%3A17%3A50

Why do Google's JS Client SDK function callbacks fail?

I'm currently in the learning phase for how the Google JS Client SDK works, since my boss needs me to learn how to integrate a Sign In button to his site to enable people to Authenticate via Google. I am testing the code for the custom Sign In button, with a touch of added functionality (like a Sign Out button), and in the process I've practically copy/pasted the code from their website. Let me show you the code first and then explain the issue, so that you can understand where the code is failing:
<script src="https://apis.google.com/js/client.js?onload=init"></script>
<script type="text/javascript">
var clientId = '{my client id here}'; // for web
var apiKey = '{my api key here}';
var scopes = 'profile email';
function SignOut() {
// I know, sloppy, but the signOut method from Google doesn't work.
window.location = 'https://accounts.google.com/logout';
// Additional code if necessary.
};
function makeApiCall() {
gapi.client.load('plus', 'v1', function () {
var request = gapi.client.plus.people.get({ 'userId': 'me' });
request.execute(function (response) {
var heading = document.createElement('h4');
var image = document.createElement('img');
image.src = response.image.url;
heading.appendChild(image);
heading.appendChild(document.createTextNode(response.displayName));
document.getElementById('name').appendChild(heading);
alert('User logged in. makeApiCall() has executed.');
})
})
};
function init() {
gapi.client.setApiKey(this.apiKey);
window.setTimeout(checkAuth, 1);
console.log('Up and ready to go.');
};
function checkAuth() {
// Triggers when the page and the SDK loads.
gapi.auth.authorize({ client_id: clientId, scope: scopes, immediate: true }, handleAuthResult);
};
function handleAuthClick(event) {
// Triggers after a user click event to ensure no popup blockers interfere.
gapi.auth.authorize({ client_id: clientId, scope: scopes, immediate: false }, handleAuthResult);
return false;
};
function handleAuthResult(authResult) {
var authorizeButton = document.getElementById('SignInBtn');
var signoutButton = document.getElementById('SignOutBtn');
if (authResult && !authResult.error) {
var V = JSON.stringify(authResult);
localStorage.setItem('GoogleAuthResult', V);
console.log(V); // Just for testing...
var authTimeout = (authResult.expires_in - 5 * 60) * 1000; setTimeout(checkAuth, authTimeout); // As recommended by a Google employee in a video, so that the token refreshes.
authorizeButton.style.display = 'none'; // Switching between Sign In and Out buttons.
signoutButton.style.display = 'inline-block';
makeApiCall();
} else {
// Immediate:true failed so user is NOT signed in.
// Make the Sign In button the one visible and prep it
// so that it executes the Immediate:false after user click:
authorizeButton.style.visibility = 'inline-block';
authorizeButton.onclick = handleAuthClick;
signoutButton.style.visibility = 'none';
}
};
</script>
The handleAuthClick function does run on the button click, but after taking the user to the Google Sign In page, when that page brings me back, the browser kinda flickers and the handleAuthResult function does not execute. Therefore, nothing changes in the page after the successful sign in; the button displayed is the Sign In button (Sign Out button not visible) and no information is displayed on the 'name' textNode. This happens on Internet Explorer (11), Firefox (39) and Chrome (44). Also, it happens at home on my laptop (straight connection to the web via Cable broadband) and at work (on Windows 8.1 behind an Active Directory).
I began wondering so I started refreshing the browser page and after a couple of refreshes, since the script runs from the beginning, the immediate:true fires again and voilá: user is connected and API call triggers.
So, on my laptop, I changed the function being called back, in the immediate:false line's callback parameter, to the init() function and that fixed the problem: everything runs smoothly from beginning to end. Yet, this is not the way it is supposed to work. I still don't know what is going on with that line.
This morning, on my computer at work (behind Active Directory), that fix didn't work. I have to refresh the page a couple of times so that the script runs from the beginning and the immediate:true triggers recognizing the user's Signed In state and displaying the proper button on screen.
Any ideas on why does this callback fail?
You need to define your apiKey in the first section of your code
var clientId = '{my client id here}'; // for web
var apiKey = '{my api key here}'
Maybe thats the problem.
Google ApiKeys

asp.net mvc3 - Loading a view always in a div

I am working on a mvc3 controller which loads a page on search. In the main index page, there is a search button and that loads another (details list) page in the given div.
I have incorporated pagination to the child view (details list). So, upon clicking on the "Next" link, it loads the next page.
cshtml of the index page: The flat id refers to where the details list loads.
<div id='FlatDetailcontainer'>Select a Project for Flat Details.. Loading...</div>
<script type="text/javascript" language="javascript">
// $(document).ready(function () {
function login() {
var check = document.getElementById("rad").value;
$("input[name=selectproj][value="+check+"]").attr('checked', true);
//document.getElementById("selectproj").checked = document.getElementById("rad").value;
if (check != "") {
handleprojselect(check);
}
}
function handleprojselect(myRadio) {
// document.getElementById("rad").value = myobj["proj"];
$.get('#Url.Action("Details", "ProjectDetails")?id=' + myRadio,
function (viewResult) {
$("#FlatDetailcontainer").html(viewResult);
});
}
function createproj() {
var url = '#Url.Action("Create")';
window.location.href = url;
}
</script>
The details page has the links of next and url action is as follows:
#if (Model.HasNextPage)
{
#Html.ActionLink("Next >", "Details", new { page = Model.PageNumber + 1 })
#Html.Raw(" ");
#Html.ActionLink(">>", "Details", new { page = Model.PageCount })
}
else
{
#:Next >
#Html.Raw(" ")
#:>>
}
However, this link always loads on a fresh page as there is no reference to the main Index page's div id. Please can someone suggest how to go ahead with this?
As far as you are loading part of the page via AJAX call you should also use AJAX to handle your pagination. You should create JS function like the following:
function nextPageClick(e)
{
e.preventDefault();
$.get($(this).attr("href"), //getting the URL from your link and loading the content via AJAX
function (viewResult) {
$("#FlatDetailcontainer").html(viewResult);
});
}
and bind it to the paging links on page load:
$(function (){
$('.nextPageLink').live('click', nextPageClick);
})
Notice that "live" jQuery method assigns click handler to the dynamically loaded content as well as on existing static content, so you have no need to reassing handler after each data reload.
You shoud add CSS class to your link to be able to locate it:
#Html.ActionLink("Next >", "Details", new { page = Model.PageNumber + 1, #class="nextPageLink" })
Of course you may use IDs or any other way to uniquely identify your pagination links.

how to write a popup window in firefox extension

I know that we can show a popup with widget or panel and the popup is around the extension icon and I know it's easy in the chrome extension development. Now I want to create a popup with javascript.
My idea is that when I click the icon button it will send a message(include the path of iframe's html page) to the content script.My code is:
nbBtn.addEventListener('click', function() {
var workers = tabs.activeTab.attach({
contentScriptFile: [ data.url("js/jquery-2.0.1.min.js"),
data.url("mycontent.js"),
data.url("js/tinybox2/packed.js"),
data.url("js/bootstrap.min.js"),
data.url("js/jquery.qrcode.min.js"),
data.url("js/2.5.3-crypto-sha1-hmac.js"),
data.url("js/moment.min.js"),
data.url("js/extension.utils.js")]
});
let content = encodeURIComponent(data.load("main.html"));
let url = "data:text/html;charset=utf-8," + content;
workers.postMessage(url);
}, false);
Then the content script show a popup with the message.The code is like that:
var showBox = function(){
if(document.getElementById(iframeId)==null){
console.log("Creating frame...");
TINY.box.show({iframe:popupSrc, width:lgmBoxWidth, height:lgmBoxHeight, top:window.innerHeight*0.1, animate:true});
}
else{
console.log("Frame already exist.");
}
}
self.on('message', function(message) {
popupSrc = message;
showBox();
});
But the iframe's html page(main.html) doesn't show normally because the js and css link(such as <link href="css/bootstrap-responsive.css" rel="stylesheet"> and <script src="js/jquery-2.0.1.min.js"></script>) in the iframe page can't work. So what can I do to solve this problem? Thanks.

iframe browser back button issue for my history.js code

Below is my code working perfectly in my page but when i am calling same page in iframe it is not working
function History.back() { alert('browser Back Clicked!'); History.forward(); };
(function(window, undefined) {
var State = History.getState();
History.replaceState({ state: 4 }, State.title, "?state=4");
})(window);

Resources