Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Bookmarklet Parse URL

    I'm trying to create two bookmarklets:

    1. Take the current URL of the page and open a new window with a URL based on the current page. Some examples (I use "->" to mean "this URL turns into that URL"):

    Code:
    http://example.com/som/faculty_staff.cfm#HeaderTitle -> https://authoring.example.com/som/login.cfm
    http://example.com/som/faculty_staff.cfm -> https://authoring.example.com/som/login.cfm
    http://example.com/som/ -> https://authoring.example.com/som/login.cfm
    http://example.com/news/webpublishing/index.cfm -> https://authoring.example.com/news/webpublishing/login.cfm
    2. Take the current URL of the page and open a URL (in the same window) based on the current page. Some examples:

    Code:
    http://example.com/som/faculty_staff.cfm#HeaderTitle -> https://authoring.example.com/som/faculty_staff.cfm
    http://example.com/som/faculty_staff.cfm -> https://authoring.example.com/som/faculty_staff.cfm
    http://example.com/som/ -> https://authoring.example.com/som/
    http://example.com/news/webpublishing/index.cfm -> https://authoring.example.com/news/webpublishing/index.cfm
    More notes:
    I plan to use these bookmarklets in sequence, first pressing 1 to log into the CMS, then pressing 2 to edit the current page.

    I started trying to figure out these problems using regexp, but I eventually gave up since regexp still confuses me to no end... Perhaps there's a non-regexp way to solve this problem? Or perhaps some regexp folks can lend a hand? I didn't see a regexp section to this forum...

    Many thanks in advance for any help!

  • #2
    Regular Coder
    Join Date
    Dec 2008
    Location
    Tannhäuser Gate
    Posts
    286
    Thanks
    7
    Thanked 58 Times in 57 Posts
    For the one to open in new window:
    Code:
    javascript:void(window.open((location.href.replace(/\w+:\/\/[w{3}\.]*/,'https://authoring.')).replace(/(\/[^\/]+$)|\/$/,'/login.cfm'),''),'0');
    and for the one to open in the same window:
    Code:
    javascript:location=(location.href.replace(/\w+:\/\/[w{3}\.]*/,'https://authoring.')).replace(/#.*/,'');
    Those should also work in case of www.example.com domain [not only example.com]

  • Users who have thanked freedom_razor for this post:

    SimonDorfman (03-17-2009)

  • #3
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I figured out the solution to bookmarklet #2:
    Code:
    javascript:void((function()
    {
    	var a=location.href.replace(/^http\:\/\/example.com\/(.*)$/,"$1");location.href="https://authoring.example.com/"+escape(a);
    }
    )())
    In bookmarklet form:
    Code:
    javascript:%20javascript:void((function()%20{var%20a=location.href.replace(/^http\:\/\/example.com\/(.*)$/,"$1");location.href="https://authoring.example.com/"+escape(a);})())
    The way I figured this out was finding some good code to copy and build off of. Namely, this Google Cache bookmarklet.

    Still scratching my head over bookmarklet #1.

    Any help would be much appreciated!

  • #4
    Regular Coder
    Join Date
    Dec 2008
    Location
    Tannhäuser Gate
    Posts
    286
    Thanks
    7
    Thanked 58 Times in 57 Posts
    I posted both bookmarklets, is there anything wrong with them?

  • #5
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you so much, freedom_razor! As I was writing my follow up post, you must have just posted your reply. These both work great!

    One odd thing was that after using the login.cfm one, I was getting an error from the CMS. I think it might be from the referrer being a non-https address.

    I think I need to add something to set document.referrer to nothing... Still looking into this...

  • #6
    Regular Coder
    Join Date
    Dec 2008
    Location
    Tannhäuser Gate
    Posts
    286
    Thanks
    7
    Thanked 58 Times in 57 Posts
    AFAIK document.referrer is a read-only property.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •