Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Best practice for opening an external URL?

Hello, all! Apologies if this is in the wrong category. Been working with Twine for a while but new to the forum. I am seeking advice on the best way to open an external URL in a new tab/window. My stories are built in Twine 2.0.11 standalone and Harlowe 1.2.2.

(1) I know that I can use something like
(link: 'foo')[(open-url: 'http://foo.bar')]
to accomplish this. I was having some problems with unexpected text showing up in the passage, but on another thread greyelf showed me how to deal with that. (Thanks!)

(2) I also know that I can use standard HTML
<a href='http://foo.bar' target='_blank'>foo</a>
markup to do this, but I don’t know how to pass story variables into the URL or even if that’s possible. If I understand correctly, I cannot just use
<a href=$foo>
or something along those lines because Harlowe doesn’t parse the text inside HTML tags as Harlowe/Twine markup. (Is that right?)

Any help/advice along these lines would be appreciated. My “stories” are actually interactive lessons for college students, delivered inside a closed system where using the standard browser back button is problematic, so sending the link into a new tab/window is pretty important to avoid disrupting the user experience.

(Also: why does the forum software add unwanted semicolons near quotation marks?)

Comments

  • You should be able to "print" the markup you want. For example:
    (print: '<a href="http://foo.bar' + $query + '" target="_blank">foo</a>')
    

    I can't recommend the (link:) variant, at least in Harlowe 1.2.2, as (open-url:) returns the window object when invoked—which gets injected into the page as the string [object Window]. I'd probably consider (open-url:) returning anything a bug—I can't think of a useful reason for it to do so, at any rate.
Sign In or Register to comment.