window.location in Firefox and Chrome giving me two different returned strings for a Google Macro

StackOverflow https://stackoverflow.com/questions/23452079

  •  15-07-2023
  •  | 
  •  

My application is using Google Apps Script HTML Service. The URL for Apps Script looks like this:

https://script.google.com/macros/s/AKfycby2Zr2apAai2sIW6eiWTc8yNakGg5M9oLQkmhcz-IRqs22qoJhm/exec

In Firefox, this line of code:

window.daURL = window.location;

returns this:

 https://script.google.com/macros/blank

Firefox puts in the word blank. Chrome gives me the entire URL. What I've been doing, is getting the entire URL, then using Javascript string methods to parse the URL for whatever info I need to check for a Facebook login. The Facebook login appends info to the end of the URL beginning with a hash tag. If the hash tag is there, the code checks for and validates a Facebook login.

I need either the entire URL, or to be able to get an appended string after the /exec.

Chrome gives me the entire URL with window.location, but Firefox will not.

If I try:

window.daURL = window.location.pathname; 

Firefox returns:

/macros/blank

If I try:

window.daURL = window.location.search;

I get nothing returned, even when a string is appended to the URL.

I can get a string appended to the URL with the Apps Scripts doGet(e) function:

e.parameter.theNameOfTheStringArg

E.g. www.URL.com?myArg=Something

Use: var getString = e.parameter.myArg

But I can't get a hashed appended value to the URL with doGet(e). I need to check for a hash in the URL.

有帮助吗?

解决方案

I figured out that I can use window.location.href to check for the existence of the hash tag appended to the url. So I use window.onload to check for a hashtag in the url, and doGet(e) to check for string attachments to the URL. I need to run both.

<script>
//Script tag in first HTML file that always loads

window.onload=function(){
  console.log("This onload did run");

  //get the URL out of the browsers address bar
  //the URL can have multiple different strings attached depending upon the situation.
  //Any situation other than something with a hashtag is initiated in the back end.

  window.daURLhash = window.location.hash;
  console.log('daURLhash: ' + daURLhash);

  window.urlHash = daURLhash.toString();
  console.log('urlHash: ' + urlHash);

  console.log("url: " + urlHash);
  //If a certain situation, there will be a hashtag in the url string
  if (urlHash != undefined && urlHash != null) {
    if (urlHash.length > 0) {
      window.hashExist = true;
      console.log('hashExist: ' + hashExist); 
    };
  };

  if (window.hashExist === true) {
     code here

</script>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top