Discussions

Expand all | Collapse all

How to get javascript to return current URL with ""return window.location.href

  • 1.  How to get javascript to return current URL with ""return window.location.href

    Posted 08-24-2018 22:53
    I have a button that I have on multiple reports that when clicked it will edit the corresponding record and then redirect to the record that was just edited. 

    However, I would like to return to the same page/report where the button was clicked. I am of the understanding that Rurl() only works with AddGen and does not work with EditRecord. 

    This is important because we are using this button to make calls through our dialer. When the button is clicked we want to be returned to the same report we were working on. The button is on multiple reports, so I can't hardcode the return URL in the formula field. 

    I know you can run javascript in a Formula Text or Formula URL field, but I cannot get it to run the javascript that should retrieve the URL. Here is the Javascript I am trying to load, but can't figure it out: 

    return window.location.href

    Here is the code for my button:

    "<a href="&URLRoot() & "db/" & Dbid() & "?act=API_EditRecord&apptoken=XXXXXXXXXXX&_fid_264=true&rid=" & [Record ID#] & "&rdr=" & URLEncode(URLRoot() & "db/" & Dbid() & "?act=dr&rid=" & [Record ID#])&">" & "<img width=24 height=24 src=\"https://phoneimage.com">"; & "</a>"

    Additionally, I am open to any options to get this to simply send me back to where I was working and not dump me into the record that I just edited. Any suggestions would be helpful. Thanks


  • 2.  RE: How to get javascript to return current URL with ""return window.location.href

    Posted 08-24-2018 23:21
    Here is a formula for a URL formula field. (Not a Rich Text formula field)

    var Text URL = URLRoot() etc up to & [Record ID#];

    //(Sorry, my ipad is not kett8ng me cut and paste. ). Be sure to end the formula variable with a semicolon.

    "javascript:" &
    "$.get('" &
    $URL &
    "',function(){" &
    "location.reload(true);" &
    "});"
    & "void(0);"

    This concept here is that you make a formula variable called URL and then that piece of JavaScript will run the URL and refresh whatever page you are on.

    You can also probably get it to work with an image too.

    If I get a chance I will post that too


  • 3.  RE: How to get javascript to return current URL with ""return window.location.href

    Posted 08-28-2018 15:40
    I was able to get this to work like a charm with a Formula URL field, however I since Quick Base does not have "Allow HTML" for Formula URL fields, I cannot get my phone icon to work inside of this field type. Here is what worked for the Formula URL field, without the phone icon. 

    var text URL= URLRoot() & "db/" & [_DBID_INBOUND_PPC] & "?act=API_EditRecord"

    & "&rid=" & URLEncode ([Record ID#])

    & "&_fid_264=" & URLEncode ([Test3])

    & "&apptoken=" & "fgxx3jb5s9nwsc7ua8keuwxq9q";

    "javascript:" &

    "$.get('" & 

    $URL&

    "',function(){" &

    "location.reload(true);" &

    "});" 

    & "void(0);"


    I have tried to put this inside of a Formula Rich Text field, which I am able to get my phone icon to work, however I cannot get the Javascript function to work properly. I have tired your Formula Rich Text field example but I am not able  to get it to accept "" & $Words & "" . It complains at the end of the formula about the syntax. 


    Any idea on how I can get it to load the javascript in either the Formula URL field or Formula Rich text field AND include my phone icon? Everything I have tried has been unsuccessful for getting the image to work in either of those two field types.  


    I just talked to Quick Base and they said that Javascript is run in a Formula URL field. not a Formula Rich Text field. 

    I can't get the Javascript to run in the Formula Rich text field, and I can't get the image to appear in the Formula URL field. 



  • 4.  RE: How to get javascript to return current URL with ""return window.location.href

    Posted 08-29-2018 08:05
    I have a working example but have been unable to get it to post in this site as I�m cycling this week and just have my ipad.

    Contact me me at QuickBaseCoach.com and I will email you an example.


  • 5.  RE: How to get javascript to return current URL with ""return window.location.href

    Posted 01-29-2019 16:17
    Hi, are you able to post the working example here? I'm running into the same thing where I'd like to include the URL in a Rich Text field but it is not reading my var text in the HTML code.



  • 6.  RE: How to get javascript to return current URL with ""return window.location.href

    Posted 07-08-2019 21:47
    I have a working example for a formula URL field that I found to work great. For whatever reason, I couldn't' get Javascript to work withint the Formula Rich Text Field after the update to that fields properties that Quick Base did.

    Mine has an IF statement but works either way. I have found that this will reload you on your current page without redirecting you to a different page. It also keeps you in the same spot of the report that you are on which is nice.  Here is my example:

    If(

    [Call Phone Trigger] = false, 

    "javascript:" &

    "$.get('" & 

    URLRoot() & "db/" & Dbid() & "?act=API_EditRecord&apptoken=xxxxxxxxx&_fid_264=true&rid=" & [Record ID#]&

    "',function(){" &

    "location.reload(true);" &

    "});" 

    & "void(0);",

    "javascript:" &

    "$.get('" & 

    URLRoot() & "db/" & Dbid() & "?act=API_EditRecord&apptoken=xxxxxxxx&_fid_264=false&rid=" & [Record ID#]&

    "',function(){" &

    "location.reload(true);" &

    "});" 

    & "void(0);")