window.location

Targeting window.location.pathname

我是研究僧i 提交于 2020-01-15 07:14:33
问题 I have a url similiar to this: www.mysite.com/products/ I was using this to test against the pathname: if (/\/products\//.test(window.location)) { _gaq.push(['_trackPageview', '/products/landing']); } But the problem I was running into was the above would execute for sub-folders as well, which I do not want: www.mysite.com/products/sub-folder/ I'm thinking window.location.pathname will help me out more than the above jQuery. But I'm unsure how to target only the top-level directory, and not

How to override window.location in Firefox?

☆樱花仙子☆ 提交于 2020-01-11 10:42:14
问题 I am trying to override the window.location in Firefox, through the following code and keep getting an error (actually want to prevent the default behavior, but I think that's not relevant) : Code : window.__defineGetter__('location', function() {}); Error redeclaration of var location I started with the suggestions at Programatically disable window.location.reload?, but didn't work. Thanks in advance, Sunil 回答1: The location property of Window is non-configurable for security reasons,

Can't go back after changing window.location.href

穿精又带淫゛_ 提交于 2020-01-06 06:10:40
问题 In my script I'm tracking what tab I am on in a web page using window.location.href = #!hashName1 If I then click on another tab, it will go to #!hashName2 My issue is, if I click the back button, it just goes back to the state #!hashName1. I have to then click back once again to go back another page. Is there any way to just have it go back a page and not back to the previous hash state? Thanks 回答1: u can handle back button event like this window.onhashchange = function() { goBack(); }

document.write in Chrome Extension

混江龙づ霸主 提交于 2020-01-04 05:34:22
问题 I'm new to this so please bear with me. I am trying to write a chrome extension that does the following: Detect www.website.com/anypage.html. If this website is detected, then do the following. Don't load the URL. Instead, write a blank document with a hyperlink to www.website.com/anypage.html?ie=UTF8 The script is set to run at document start (in the manifest). Here is my code: Detect URL: var regExp = /website.com/gi; var match = 0; testString = window.location.href.toString(); if(regExp

window.top.location vs window.location

独自空忆成欢 提交于 2020-01-01 11:36:09
问题 how to sync window.top.location and window.location? 回答1: This is how you set the parent of the frame ( top ) to the location of the frame document... top.location = self.location; Of course, this code must be executed within the iframe, and is succeptible to the Same-Origin Policy. 回答2: window.top.location is return you to broswer's address bar location even you'r in i-frame or page.. window.location is return location of your current page address in case facebook apps. if you want to top

Calling a javascript function after loading a page with window.location.assign

╄→尐↘猪︶ㄣ 提交于 2019-12-31 04:31:05
问题 Is it possible to call a javascript function after loading a page with window.location.assign? I have this code. <script language="javascript" type="text/javascript"> function Loadspirit(){ window.location.assign("spirituality.php"); ReadEnglish(); } </script> I load the page then call ReadEnglish(), a function defined in spirituality.php. The function doesn't execute. What would be the way to make the function execute? 回答1: As soon as you assign a new window.location, the browser starts

window.location.href doesn't redirect

穿精又带淫゛_ 提交于 2019-12-30 07:54:14
问题 I know this is a question much discussed but I can't figure out why it does not work for me. This is my function: function ShowComments(){ alert("fired"); var movieShareId = document.getElementById('movieId'); //alert("found div" + movieShareId.textContent || movieShareId.innerText); //alert("redirect location: /comments.aspx?id=" + movieShareId.textContent || movieShareId.innerText + "/"); window.location.href = "/comments.aspx?id=" + movieShareId.textContent || movieShareId.innerText + "/";

Google apps script location.reload in web app

笑着哭i 提交于 2019-12-30 04:47:09
问题 I am using a GAS web app that needs to refresh its contents when a user takes certain actions (like clicking on a particular div). On the clientside, I have this script that gets called from onclick google.script.run.withSuccessHandler(refreshCallback).myServersideFunction(); function refreshCallback(roomsPlus) { var statusDiv = document.getElementById("status"); statusDiv.innerHTML = "Reloading..."; window.location.reload(true); }; The status div changes to "Reloading..." so I know the

how do I detect if window.location failed?

烂漫一生 提交于 2019-12-29 06:53:10
问题 how do I check if a call to window.location failed because the given URL was invalid, etc? Is there some event I can set on the window object or on some other object that can catch this? 回答1: Finally got it to work using a "workaround" that is not a generic solution as I originally hoped: I am using the fact that the link I am trying to open is a custom url scheme (e.g. myxx://localhost) on mobile, and if it fails, the action I want to perform is a redirection to a standard appstore URL (os

If window.location ends with html execute javascript

空扰寡人 提交于 2019-12-25 12:45:57
问题 Execute javascript if current location contains html in in. I have tried the below but it doesn't work var winloc = window.location; //for e.g http://mysite.com/home.html var ishtml = winloc.match(/html/$); var dothtml = "html"; if(dothtml==ishtml){ //execute javascript here } 回答1: var isHTML = "html" === window.location.pathname.split(".").pop().toLowerCase(); if ( isHTML ) { //execute javascript here } See Amaan answer using regexp: https://stackoverflow.com/a/8619635/887539 回答2: var winloc