html5-history

Possible to get query parameters of the <script> src JavaScript URL?

家住魔仙堡 提交于 2019-12-24 06:39:04
问题 As an example, I have the following html: <body> <script src="code.js?q=xyz"></script> </body> I want to be able to read the q=xyz query parameter from within code.js . I tried: console.log(window.location.href) But it gives me the html document's URL, not code.js 's URL (I could then parse the URL for the query parameters). Is there any way to get an imported JavaScript file's query parameters from within that JavaScript? I know I could read the query parameters on a server and then send

webpack historyApiFallback configuration for deep routes

大兔子大兔子 提交于 2019-12-24 00:46:40
问题 webpack-dev-server can be set up to send you back to index.html and find your scripts for a single route like http://localhost:4301/sdr but when you put in a deeper route (or a single route with a / at the end) http://localhost:4301/sdr/dog it gets confused. devServer: { contentBase: './dist', historyApiFallback: true }, with http://localhost:4301/sdr/dog the server responds x GET http://localhost:4301/sdr/bundle.js adding /sdr to the the path in its search for bundle.js How can I fix this. .

Javascript history state incorrect

别来无恙 提交于 2019-12-23 09:02:13
问题 I am trying to populate the index of the currently selected tab using history.pushState({tabSelected: 1}, null, ""); I have a handler to the popstate event in jquery which programmatically switches the jquery ui tabs. $(window).bind("popstate", function(event) { var state = event.originalEvent.state; ... } This works fine and the browser and I am able to switch between tabs using back and forward buttons. Also works with two layers of tabs. But in certain cases I want to push additional state

stop firing popstate on hashchange

ε祈祈猫儿з 提交于 2019-12-23 07:33:28
问题 I am working with the History API and using push and pop state. I want to stop the popstate event from firing in some scenario where I am only appending the hash to URL. for example in some cases on click of anchor it appends # to the URL and popstate is immediately fired) I want to avoid all the scenarios where # or #somehasvalue is appended to the URL and stop popstate from firing. I am mainitaing the URL's with query parameters and I do not have any scenario where I need the popstate event

Why is event.state on window.onpopstate empty when pushing with same location.href (or empty)

狂风中的少年 提交于 2019-12-23 07:26:51
问题 When pushing to history and setting data without changing URL: window.history.pushState({ stateName: "myStateName", randomData: window.Math.random() }, "myStateName", location.href); .... and then listen to the pop event and trigger it by pressing the Back button in the browser: window.onpopstate = function(event) { console.log(event.state); //logs null } You will most of the time get null as the state value instead of: { stateName: "myStateName", randomData: 0.34234234234 } How can I solve

history.pushState does not update url for “share …” button on mobile Chrome

与世无争的帅哥 提交于 2019-12-22 10:34:44
问题 I am using history.pushState to update URL as below: var state = {url: newLocation}; window.history.pushState(state, pagetitle, newLocation); On Mobile Chrome, the webpage URL (on the URL bar) and title do get updated as expected. But when clicking on the "Share..." button on the Chrome menu, the old URL (before calling history.pushState) is shared instead. Am I missing anything and how can I fix it? Thanks! 回答1: I found out that the rel="canonical" url should also be updated. $('link[rel=

Updating address bar window.location hash with scrollspy

荒凉一梦 提交于 2019-12-21 21:46:35
问题 I've got a menu with scrollspy (using twitter boostrap). I want update the window.location.hash when the user scrolls down to a next section. The following code works when the user scrolls down: $(window).on('activate.bs.scrollspy', function (e) { location.hash = $("a[href^='#']", e.target).attr("href") || location.hash; }); However it does not work very well when the user scrolls upwards. The reason for this is that setting a new location.hash triggers the browser to navigate towards that

It is possible to set the href attribute of a base tag in AngularJs?

為{幸葍}努か 提交于 2019-12-21 13:10:10
问题 I want to set the href attribute value of base tag based on a constant value. To do so I've declared the base attribute in the head element as follows: <head> <base ng-href="{{baseUrl}}"> </head> and I set the baseUrl value with this code snippet: app.run(["$rootScope","env", function($rootScope, env){ $rootScope.baseUrl = env.baseUrl; }]); where env is the Angular constant. The locationProvider is configured in this way: .config(function ($locationProvider) { $locationProvider.html5Mode(true

Facebook chatbox doesn't reload between pages

断了今生、忘了曾经 提交于 2019-12-21 05:12:23
问题 I observed this feature in Facebook, that when you have a chat box opened at the bottom right, and you go to another page, say, your friend's profile, or some photo collection page within Facebook, the chat box doesn't reload, it remains where it is (as if in a separate layer on top of the background page). So naturally, I thought that Facebook isn't reloading the page per se, it is using history.pushstate and related functions to load the content asynchronously, and changing the URL

using history.pushState in Firefox make my favicon disappear

喜你入骨 提交于 2019-12-19 07:57:06
问题 using something like history.pushState(null, document.title, "?#"); in my site make my favicon disappear in Firefox, But it works in chrome Is it a javascript/jQuery way to add favicon when the page is loading? 回答1: I had similar issue in IE. Whenever I called history.replaceState() favicon disappeared. Favicon was included via link tag like this: <link rel="shortcut icon" href="/img/resources/favicon.ico" type="image/x-icon"> After I placed favicon.ico to the root folder of my application