window.location

How to detect change of window hash?

白昼怎懂夜的黑 提交于 2019-12-19 20:46:12
问题 How can you detect a window.location.hash onchange, for example I could do this: if(window.location.hash.hasChanged()) { // ajax stuff } else { // nothing, no hash has been changed (without any window reload) } If I change the hash, e.g. edits and change the hash by pressing enter after editing nothing happens, only on a window reload will detect a change in the hash. 回答1: Ben Alman's hashchange jQuery plugin provides the ability to monitor the hash for changes. 回答2: Most recent browsers (FF3

Is JavaScript location.href call is asynchronous?

有些话、适合烂在心里 提交于 2019-12-19 05:23:12
问题 function fun(){ console.log("Hi"); window.location.href="http://www.google.com"; console.log("Hello, how are you"); alert("I am good"); fun1(); } function fun1(){ console.log("Whats up??"); } If you see the above lines of code the location.href is getting called before console.log("Hello, how are you"), alert and fun1(). when I call the fun() it executes all the statements below location.href and then it redirects to https://www.google.com . So my question is , "Is location.href call is

Window.Location Not Working In IE?

孤人 提交于 2019-12-18 06:59:37
问题 I have been trying to figure this out all afternoon, but have given up and now turning to you clever people to help :) I have the following Jquery/Javascript function, which is working fine in Chrome - BUT in IE nothing happens? $(".btnsubmitpost").click(function () { var topicid = $(this).attr('rel'); var sbody = tinyMCE.get('txtPost').getContent(); $('.topicpostlistnewpost').remove(); $('.postsuccess').show(); $.post("/myurl/" + topicid + ".aspx", { "postcontent": sbody }, function (data) {

How can I make a HTML a href hyperlink open a new window using window.location?

蹲街弑〆低调 提交于 2019-12-17 22:36:17
问题 This is my code: <a href="http://www.google.com" onClick="window.location.href='http://www.yahoo.com';return false;" target="_blank">test</a> When you click it, it takes you to Yahoo but it does not open a new window? 回答1: <a href="#" onClick="window.open('http://www.yahoo.com', '_blank')">test</a> Easy as that. Or without JS <a href="http://yahoo.com" target="_blank">test</a> 来源: https://stackoverflow.com/questions/13335954/how-can-i-make-a-html-a-href-hyperlink-open-a-new-window-using

Is there any difference with using only location vs using window.location across browsers

天大地大妈咪最大 提交于 2019-12-17 19:46:43
问题 I find myself always writing: console.log(window.location.href); without even thinking about it. The majority of answers on SO also write it this way. Is there any reason why I can't just write: location.href since location is an object at window level? Are there any cross-browser compatibility issues with this? To Clarify: I know there is document.location - that is NOT what this question is about. This is about if there is any difference with using only location vs using window.location

Assigning `var location` in global scope redirects to non-existent file

痴心易碎 提交于 2019-12-13 03:47:03
问题 I have an HTML file test.html where I have two variables both named location , one global and one local. But when I open it in browser it just says Your file was not found , and the address bar shows file://Los%20Angeles instead of file://test.html as expected. Why? <html> <body> <script type="text/javascript"> var location = "Los Angeles" function showLocation() { var location = "San Francisco" document.write(location) } </script> <input type="button" onclick="showLocation()" value="Show

Using window.location.hash in jQuery

拜拜、爱过 提交于 2019-12-12 11:16:21
问题 I would like to make a color fading navigation menu using jQuery, in which the "pressed" button corresponding to the current page behaves differently from the "unpressed" button (specifically, it doesn't fade to a different color upon hovering). If I look at the example at www.guitaracademy.nl, I see that they use native javascript with the window.location.hash property. However, I can't seem to get this hash into jQuery. Here is an example script: <html> <head> <script type="text/javascript"

What is the difference between PHP header and Javascript window.location?

旧时模样 提交于 2019-12-12 05:39:10
问题 So yeah this came to mind randomly when I was teaching someone how to redirect their page. I wasn't really sure what the main difference was... Is there a reason you would use one over the other? I guess if you are not coding in PHP, you would have to use the Javascript window.location to redirect but would you ever use window.location over PHP header if you were developing in PHP? I feel they have very similar functions but perhaps I am missing something. 回答1: The browser will process the

What is the difference in “/urlString.html” versus “urlString.html” in window.location?

徘徊边缘 提交于 2019-12-11 19:02:08
问题 I recently ran into an issue when preparing a web app to work in IE11. I've found a working solution but I would prefer to have a good reason why it worked rather than a guess. My issue was an incorrect path when redirecting from the URL (http: //localhost:4724/View/Completion) to an exit page using the following javascript: window.location = "Exit.aspx?timeout=true"; This resulted in a URL like so in IE11. Note the extra /View/: http: //localhost:4724/View/Exit.aspx?timeout=true In Chrome it

Angular testing Service method with window.location.replace

点点圈 提交于 2019-12-11 15:31:43
问题 In my Angular 4 application, I need to test a method of a Service which at some point it calls a private method of the same service having: window.location.replace(url); When the test reach that line, the karma-runner browser gets redirected to the url which of course is not what I want. If I try to spy it, I get: Error: <spyOn> : replace is not declared writable or has no setter How can I correctly test my method? 回答1: location object is read-only property, and its properties are read-only